pkg_test.go 3.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright 2018 The kubecfg authors
//
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// +build e2e

package e2e

import (
	"path/filepath"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ks pkg", func() {
	var a app

	BeforeEach(func() {
		a = e.initApp("")
	})

bryanl's avatar
bryanl committed
34
	Describe("add", func() {
35 36 37 38 39 40 41 42 43
		Context("incubator/apache", func() {
			It("describes the package", func() {
				o := a.runKs("pkg", "describe", "incubator/apache")
				assertExitStatus(o, 0)
				assertOutput("pkg/describe/output.txt", o.stdout)
			})
		})
	})

bryanl's avatar
bryanl committed
44
	Describe("describe", func() {
bryanl's avatar
bryanl committed
45 46
		Context("registry incubator/apache", func() {
			It("describes the registry package", func() {
bryanl's avatar
bryanl committed
47
				o := a.runKs("pkg", "describe", "incubator/apache")
48
				assertExitStatus(o, 0)
bryanl's avatar
bryanl committed
49 50 51
				assertOutput("pkg/describe/output.txt", o.stdout)
			})
		})
bryanl's avatar
bryanl committed
52 53 54 55 56 57 58 59 60
		Context("library apache", func() {
			It("describes the library package", func() {
				a.pkgInstall("incubator/apache")

				o := a.runKs("pkg", "describe", "apache")
				assertExitStatus(o, 0)
				assertOutput("pkg/describe/output.txt", o.stdout)
			})
		})
bryanl's avatar
bryanl committed
61 62 63 64 65 66 67 68
	})

	Describe("install", func() {
		Context("github based part", func() {
			Context("incubator/apache", func() {
				It("describes the package", func() {
					o := a.runKs("pkg", "install", "incubator/apache")
					assertExitStatus(o, 0)
69

bryanl's avatar
bryanl committed
70 71 72
					pkgDir := filepath.Join(a.dir, "vendor", "incubator", "apache")
					Expect(pkgDir).To(BeADirectory())
				})
73 74
			})
		})
bryanl's avatar
bryanl committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

		Context("fs based part", func() {
			Context("local/contour", func() {
				It("describes the package", func() {
					path, err := filepath.Abs(filepath.Join("testdata", "registries", "parts-infra"))
					Expect(err).ToNot(HaveOccurred())

					o := a.registryAdd("local", path)

					o = a.runKs("pkg", "install", "local/contour")
					assertExitStatus(o, 0)

					o = a.pkgList()

					m := map[string]interface{}{}
					tPath := filepath.Join("pkg", "install", "fs-output.txt.tmpl")
					assertTemplate(m, tPath, o.stdout)
				})
			})
		})

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
	})

	Describe("list", func() {
		It("lists available packages", func() {
			o := a.runKs("pkg", "list")
			assertExitStatus(o, 0)
			assertOutput("pkg/list/output.txt", o.stdout)
		})
	})

	Context("use", func() {
		It("generates a component using the prototype", func() {
			o := a.runKs(
				"prototype", "use", "deployed-service", "guestbook-ui",
				"--image", "gcr.io/heptio-images/ks-guestbook-demo:0.1",
				"--type", "ClusterIP")
			assertExitStatus(o, 0)

			component := filepath.Join(a.dir, "components", "guestbook-ui.jsonnet")
			assertContents("generate/guestbook-ui.jsonnet", component)

			params := filepath.Join(a.dir, "components", "params.libsonnet")
			assertContents("generate/params.libsonnet", params)
		})
	})

})