|
1 | 1 | package configmanager |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + |
4 | 7 | . "github.com/onsi/ginkgo/v2" |
5 | 8 | . "github.com/onsi/gomega" |
6 | 9 | ) |
7 | 10 |
|
8 | 11 | var _ = Describe("newRawConfigFromConfigText func", func() { |
9 | 12 | var testText []byte |
10 | | - When("text is valid", func() { |
11 | | - BeforeEach(func() { |
12 | | - testText = []byte(`--- |
13 | | -config: |
| 13 | + const ( |
| 14 | + validConfigTextWithoutKey = ` |
14 | 15 | state: |
15 | 16 | backend: local |
16 | 17 | options: |
17 | | - stateFile: devstream.state |
18 | | -vars: |
19 | | - tests: argocd |
20 | | -apps: |
| 18 | + stateFile: devstream.state` |
| 19 | + validVarsTextWithoutKey = ` |
| 20 | + tests: argocd` |
| 21 | + validAppsTextWithoutKey = ` |
21 | 22 | - name: service-a |
22 | 23 | spec: |
23 | 24 | language: python |
24 | | - framework: [[ var1 ]]/[[ var2 ]]_gg |
25 | | -not_exist: 123`) |
| 25 | + framework: [[ var1 ]]/[[ var2 ]]_gg` |
| 26 | + ) |
| 27 | + When("text is valid", func() { |
| 28 | + BeforeEach(func() { |
| 29 | + testText = []byte(fmt.Sprintf(`--- |
| 30 | +config:%s |
| 31 | +vars:%s |
| 32 | +apps:%s`, validConfigTextWithoutKey, validVarsTextWithoutKey, validAppsTextWithoutKey)) |
26 | 33 | }) |
27 | 34 | It("should return config map", func() { |
28 | 35 | rawMap, err := newRawConfigFromConfigBytes(testText) |
29 | 36 | Expect(err).ShouldNot(HaveOccurred()) |
30 | | - Expect(string(rawMap.apps)).Should(Equal(` |
31 | | -- name: service-a |
32 | | - spec: |
33 | | - language: python |
34 | | - framework: [[ var1 ]]/[[ var2 ]]_gg |
35 | | -`)) |
36 | | - Expect(string(rawMap.config)).Should(Equal(` |
37 | | - state: |
38 | | - backend: local |
39 | | - options: |
40 | | - stateFile: devstream.state |
41 | | -`)) |
42 | | - Expect(string(rawMap.vars)).Should(Equal(` |
43 | | - tests: argocd |
44 | | -`)) |
| 37 | + removeLineFeed := func(s string) string { |
| 38 | + return strings.ReplaceAll(s, "\n", "") |
| 39 | + } |
| 40 | + Expect(removeLineFeed(string(rawMap.apps))).Should(Equal(removeLineFeed(validAppsTextWithoutKey))) |
| 41 | + Expect(removeLineFeed(string(rawMap.config))).Should(Equal(removeLineFeed(validConfigTextWithoutKey))) |
| 42 | + Expect(removeLineFeed(string(rawMap.vars))).Should(Equal(removeLineFeed(validVarsTextWithoutKey))) |
45 | 43 | }) |
46 | 44 | }) |
47 | | - When("text is not valid", func() { |
48 | | - BeforeEach(func() { |
49 | | - testText = []byte(` |
50 | | -not_valid: not_exist |
51 | | -`) |
| 45 | + When("text is invalid", func() { |
| 46 | + When("invalid keys are used", func() { |
| 47 | + BeforeEach(func() { |
| 48 | + testText = []byte(fmt.Sprintf(`--- |
| 49 | +config: |
| 50 | +%s |
| 51 | +vars: |
| 52 | +%s |
| 53 | +app: |
| 54 | +%s`, validConfigTextWithoutKey, validVarsTextWithoutKey, validAppsTextWithoutKey)) |
| 55 | + }) |
| 56 | + It("should return error", func() { |
| 57 | + _, err := newRawConfigFromConfigBytes(testText) |
| 58 | + Expect(err).Should(HaveOccurred()) |
| 59 | + }) |
52 | 60 | }) |
53 | | - It("should return error", func() { |
54 | | - _, err := newRawConfigFromConfigBytes(testText) |
55 | | - Expect(err).Error().Should(HaveOccurred()) |
| 61 | + |
| 62 | + When("there are no enough keys", func() { |
| 63 | + BeforeEach(func() { |
| 64 | + testText = []byte(fmt.Sprintf(` |
| 65 | +config: |
| 66 | +%s |
| 67 | +`, validConfigTextWithoutKey)) |
| 68 | + }) |
| 69 | + It("should return error", func() { |
| 70 | + _, err := newRawConfigFromConfigBytes(testText) |
| 71 | + Expect(err).Error().Should(HaveOccurred()) |
| 72 | + }) |
56 | 73 | }) |
57 | 74 | }) |
| 75 | + |
58 | 76 | }) |
59 | 77 |
|
60 | 78 | var _ = Describe("rawConfig struct", func() { |
|
0 commit comments