registry_test.go 3.91 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
// +build e2e

package e2e

import (
bryanl's avatar
bryanl committed
21 22
	"path/filepath"

23
	. "github.com/onsi/ginkgo"
bryanl's avatar
bryanl committed
24
	. "github.com/onsi/gomega"
25 26 27 28 29 30 31 32 33 34
)

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

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

bryanl's avatar
bryanl committed
35
	Describe("add", func() {
36 37 38 39
		Context("global", func() {
			var add = func(path string) {
				o := a.runKs("registry", "add", "local", path)
				assertExitStatus(o, 0)
bryanl's avatar
bryanl committed
40

41 42 43 44
				uri := convertPathToURI(path)
				m := map[string]interface{}{
					"uri": uri,
				}
bryanl's avatar
bryanl committed
45

46 47 48 49
				o = a.registryList()

				tPath := filepath.Join("registry", "add", "output.txt.tmpl")
				assertTemplate(m, tPath, o.stdout)
bryanl's avatar
bryanl committed
50 51
			}

52 53 54 55 56
			Context("a filesystem based registry", func() {
				Context("as a path", func() {
					It("adds a registry", func() {
						path, err := filepath.Abs(filepath.Join("testdata", "registries", "parts-infra"))
						Expect(err).ToNot(HaveOccurred())
bryanl's avatar
bryanl committed
57

58 59 60 61 62 63 64
						add(path)
					})
				})
				Context("as a URL", func() {
					It("adds a registry", func() {
						path, err := filepath.Abs(filepath.Join("testdata", "registries", "parts-infra"))
						Expect(err).ToNot(HaveOccurred())
bryanl's avatar
bryanl committed
65

66 67 68 69 70 71 72 73 74 75 76 77 78
						uri := convertPathToURI(path)

						add(uri)
					})
				})
			})
		})

		Context("override", func() {
			var add = func(name, path string) {
				o := a.runKs("registry", "add", "--override", name, path)
				assertExitStatus(o, 0)
			}
bryanl's avatar
bryanl committed
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
			Context("a filesystem based registry", func() {
				Context("as a path", func() {
					It("adds a registry", func() {
						path, err := filepath.Abs(filepath.Join("testdata", "registries", "parts-infra"))
						Expect(err).ToNot(HaveOccurred())

						add("local", path)

						o := a.registryList()

						uri := convertPathToURI(path)
						m := map[string]interface{}{
							"uri": uri,
						}
						tPath := filepath.Join("registry", "add", "override-output.txt.tmpl")
						assertTemplate(m, tPath, o.stdout)
					})
				})
				Context("as a URL", func() {
					It("adds a registry", func() {
						path, err := filepath.Abs(filepath.Join("testdata", "registries", "parts-infra"))
						Expect(err).ToNot(HaveOccurred())

						uri := convertPathToURI(path)

						add("local", uri)

						o := a.registryList()

						m := map[string]interface{}{
							"uri": uri,
						}
						tPath := filepath.Join("registry", "add", "override-output.txt.tmpl")
						assertTemplate(m, tPath, o.stdout)
					})
bryanl's avatar
bryanl committed
115 116
				})
			})
117 118 119

			Context("an existing configuration", func() {
				It("overrides the existing configuration", func() {
bryanl's avatar
bryanl committed
120 121 122
					path, err := filepath.Abs(filepath.Join("testdata", "registries", "parts-infra"))
					Expect(err).ToNot(HaveOccurred())

123
					add("incubator", path)
bryanl's avatar
bryanl committed
124

125 126 127 128 129 130 131 132
					o := a.registryList()

					uri := convertPathToURI(path)
					m := map[string]interface{}{
						"uri": uri,
					}
					tPath := filepath.Join("registry", "add", "override-incubator.txt.tmpl")
					assertTemplate(m, tPath, o.stdout)
bryanl's avatar
bryanl committed
133 134 135 136 137
				})
			})
		})
	})

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
	Describe("list", func() {
		It("lists the currently configured registries", func() {
			o := a.runKs("registry", "list")
			assertExitStatus(o, 0)
			assertOutput("registry/list/output.txt", o.stdout)
		})
	})

	Describe("describe", func() {
		Context("incubator", func() {
			It("describe a registry", func() {
				o := a.runKs("registry", "describe", "incubator")
				assertExitStatus(o, 0)
				assertOutput("registry/describe/output.txt", o.stdout)
			})
		})
	})
})