+112
-26
lines changedFilter options
+112
-26
lines changed Original file line number Diff line number Diff line change
@@ -86,6 +86,9 @@ type IndexFile struct {
86
86
87
87
// IndexValidation is used to validate the integrity of an index file
88
88
type IndexValidation struct {
89
+
// This is used ONLY for validation against chartmuseum's index files and
90
+
// is discarded after validation.
91
+
ServerInfo map[string]interface{} `yaml:"serverInfo,omitempty"`
89
92
APIVersion string `yaml:"apiVersion"`
90
93
Generated time.Time `yaml:"generated"`
91
94
Entries map[string]interface{} `yaml:"entries"`
Original file line number Diff line number Diff line change
@@ -30,9 +30,31 @@ import (
30
30
)
31
31
32
32
const (
33
-
testfile = "testdata/local-index.yaml"
34
-
unorderedTestfile = "testdata/local-index-unordered.yaml"
35
-
testRepo = "test-repo"
33
+
testfile = "testdata/local-index.yaml"
34
+
chartmuseumtestfile = "testdata/chartmuseum-index.yaml"
35
+
unorderedTestfile = "testdata/local-index-unordered.yaml"
36
+
testRepo = "test-repo"
37
+
indexWithDuplicates = `
38
+
apiVersion: v1
39
+
entries:
40
+
nginx:
41
+
- urls:
42
+
- https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz
43
+
name: nginx
44
+
description: string
45
+
version: 0.2.0
46
+
home: https://github.com/something/else
47
+
digest: "sha256:1234567890abcdef"
48
+
nginx:
49
+
- urls:
50
+
- https://kubernetes-charts.storage.googleapis.com/alpine-1.0.0.tgz
51
+
- http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
52
+
name: alpine
53
+
description: string
54
+
version: 1.0.0
55
+
home: https://github.com/something
56
+
digest: "sha256:1234567890abcdef"
57
+
`
36
58
)
37
59
38
60
func TestIndexFile(t *testing.T) {
@@ -79,15 +101,42 @@ func TestIndexFile(t *testing.T) {
79
101
}
80
102
81
103
func TestLoadIndex(t *testing.T) {
82
-
b, err := ioutil.ReadFile(testfile)
83
-
if err != nil {
84
-
t.Fatal(err)
104
+
tests := []struct {
105
+
Name string
106
+
Filename string
107
+
}{
108
+
{
109
+
Name: "regular index file",
110
+
Filename: testfile,
111
+
},
112
+
{
113
+
Name: "chartmuseum index file",
114
+
Filename: chartmuseumtestfile,
115
+
},
85
116
}
86
-
i, err := loadIndex(b)
87
-
if err != nil {
88
-
t.Fatal(err)
117
+
118
+
for _, tc := range tests {
119
+
tc := tc
120
+
t.Run(tc.Name, func(t *testing.T) {
121
+
t.Parallel()
122
+
b, err := ioutil.ReadFile(tc.Filename)
123
+
if err != nil {
124
+
t.Fatal(err)
125
+
}
126
+
i, err := loadIndex(b)
127
+
if err != nil {
128
+
t.Fatal(err)
129
+
}
130
+
verifyLocalIndex(t, i)
131
+
})
132
+
}
133
+
}
134
+
135
+
// TestLoadIndex_Duplicates is a regression to make sure that we don't non-deterministically allow duplicate packages.
136
+
func TestLoadIndex_Duplicates(t *testing.T) {
137
+
if _, err := loadIndex([]byte(indexWithDuplicates)); err == nil {
138
+
t.Errorf("Expected an error when duplicate entries are present")
89
139
}
90
-
verifyLocalIndex(t, i)
91
140
}
92
141
93
142
func TestLoadIndexFile(t *testing.T) {
@@ -422,19 +471,3 @@ func TestIndexAdd(t *testing.T) {
422
471
t.Errorf("Expected http://example.com/charts/deis-0.1.0.tgz, got %s", i.Entries["deis"][0].URLs[0])
423
472
}
424
473
}
425
-
426
-
const mockDuplicateIndex = `
427
-
entries:
428
-
foo: {}
429
-
bar: {}
430
-
baz: {}
431
-
bar: {}
432
-
`
433
-
434
-
func TestValidateIndex(t *testing.T) {
435
-
expect := `key "bar" already set in map`
436
-
err := validateIndex([]byte(mockDuplicateIndex))
437
-
if strings.Contains(expect, err.Error()) {
438
-
t.Errorf("Unexpected error: %s", err)
439
-
}
440
-
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
1
+
serverInfo:
2
+
contextPath: /v1/helm
3
+
apiVersion: v1
4
+
entries:
5
+
nginx:
6
+
- urls:
7
+
- https://kubernetes-charts.storage.googleapis.com/nginx-0.2.0.tgz
8
+
name: nginx
9
+
description: string
10
+
version: 0.2.0
11
+
home: https://github.com/something/else
12
+
digest: "sha256:1234567890abcdef"
13
+
keywords:
14
+
- popular
15
+
- web server
16
+
- proxy
17
+
- urls:
18
+
- https://kubernetes-charts.storage.googleapis.com/nginx-0.1.0.tgz
19
+
name: nginx
20
+
description: string
21
+
version: 0.1.0
22
+
home: https://github.com/something
23
+
digest: "sha256:1234567890abcdef"
24
+
keywords:
25
+
- popular
26
+
- web server
27
+
- proxy
28
+
alpine:
29
+
- urls:
30
+
- https://kubernetes-charts.storage.googleapis.com/alpine-1.0.0.tgz
31
+
- http://storage2.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
32
+
name: alpine
33
+
description: string
34
+
version: 1.0.0
35
+
home: https://github.com/something
36
+
keywords:
37
+
- linux
38
+
- alpine
39
+
- small
40
+
- sumtin
41
+
digest: "sha256:1234567890abcdef"
42
+
chartWithNoURL:
43
+
- name: chartWithNoURL
44
+
description: string
45
+
version: 1.0.0
46
+
home: https://github.com/something
47
+
keywords:
48
+
- small
49
+
- sumtin
50
+
digest: "sha256:1234567890abcdef"
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4