mirror of https://github.com/helm/helm
commit
a4f00f08b9
@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kubernetes/helm/pkg/repo"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testDir = "testdata/"
|
||||
const testFile = "testdata/local-cache.yaml"
|
||||
|
||||
type searchTestCase struct {
|
||||
in string
|
||||
expectedOut []string
|
||||
}
|
||||
|
||||
var searchTestCases = []searchTestCase{
|
||||
{"foo", []string{}},
|
||||
{"alpine", []string{"alpine-1.0.0"}},
|
||||
{"sumtin", []string{"alpine-1.0.0"}},
|
||||
{"web", []string{"nginx-0.1.0"}},
|
||||
}
|
||||
|
||||
var searchCacheTestCases = []searchTestCase{
|
||||
{"notthere", []string{}},
|
||||
{"odd", []string{"foobar/oddness-1.2.3"}},
|
||||
{"sumtin", []string{"local/alpine-1.0.0", "foobar/oddness-1.2.3"}},
|
||||
{"foobar", []string{"foobar/foobar-0.1.0"}},
|
||||
{"web", []string{"local/nginx-0.1.0"}},
|
||||
}
|
||||
|
||||
func validateEntries(t *testing.T, in string, found []string, expected []string) {
|
||||
if len(found) != len(expected) {
|
||||
t.Errorf("Failed to search %s: Expected: %#v got: %#v", in, expected, found)
|
||||
}
|
||||
foundCount := 0
|
||||
for _, exp := range expected {
|
||||
for _, f := range found {
|
||||
if exp == f {
|
||||
foundCount = foundCount + 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
if foundCount != len(expected) {
|
||||
t.Errorf("Failed to find expected items for %s: Expected: %#v got: %#v", in, expected, found)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func searchTestRunner(t *testing.T, tc searchTestCase) {
|
||||
cf, err := repo.LoadCacheFile(testFile)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to load cache file : %s : %s", testFile, err)
|
||||
}
|
||||
|
||||
u := searchChartRefsForPattern(tc.in, cf.Entries)
|
||||
validateEntries(t, tc.in, u, tc.expectedOut)
|
||||
}
|
||||
|
||||
func searchCacheTestRunner(t *testing.T, tc searchTestCase) {
|
||||
u, err := searchCacheForPattern(testDir, tc.in)
|
||||
if err != nil {
|
||||
t.Errorf("searchCacheForPattern failed: %#v", err)
|
||||
}
|
||||
validateEntries(t, tc.in, u, tc.expectedOut)
|
||||
}
|
||||
|
||||
func TestSearches(t *testing.T) {
|
||||
for _, tc := range searchTestCases {
|
||||
searchTestRunner(t, tc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheSearches(t *testing.T) {
|
||||
for _, tc := range searchCacheTestCases {
|
||||
searchCacheTestRunner(t, tc)
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
foobar-0.1.0:
|
||||
url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
|
||||
name: foobar
|
||||
description: string
|
||||
version: 0.1.0
|
||||
home: https://github.com/foo
|
||||
keywords:
|
||||
- dummy
|
||||
- hokey
|
||||
oddness-1.2.3:
|
||||
url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
|
||||
name: oddness
|
||||
description: string
|
||||
version: 1.2.3
|
||||
home: https://github.com/something
|
||||
keywords:
|
||||
- duck
|
||||
- sumtin
|
@ -0,0 +1,22 @@
|
||||
nginx-0.1.0:
|
||||
url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
|
||||
name: nginx
|
||||
description: string
|
||||
version: 0.1.0
|
||||
home: https://github.com/something
|
||||
keywords:
|
||||
- popular
|
||||
- web server
|
||||
- proxy
|
||||
alpine-1.0.0:
|
||||
url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
|
||||
name: alpine
|
||||
description: string
|
||||
version: 1.0.0
|
||||
home: https://github.com/something
|
||||
keywords:
|
||||
- linux
|
||||
- alpine
|
||||
- small
|
||||
- sumtin
|
||||
|
@ -0,0 +1,41 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testfile = "testdata/local-cache.yaml"
|
||||
|
||||
func TestLoadCacheFile(t *testing.T) {
|
||||
cf, err := LoadCacheFile(testfile)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to load cachefile: %s", err)
|
||||
}
|
||||
if len(cf.Entries) != 2 {
|
||||
t.Errorf("Expected 2 entries in the cache file, but got %d", len(cf.Entries))
|
||||
}
|
||||
nginx := false
|
||||
alpine := false
|
||||
for k, e := range cf.Entries {
|
||||
if k == "nginx-0.1.0" {
|
||||
if e.Name == "nginx" {
|
||||
if len(e.Keywords) == 3 {
|
||||
nginx = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if k == "alpine-1.0.0" {
|
||||
if e.Name == "alpine" {
|
||||
if len(e.Keywords) == 4 {
|
||||
alpine = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !nginx {
|
||||
t.Errorf("nginx entry was not decoded properly")
|
||||
}
|
||||
if !alpine {
|
||||
t.Errorf("alpine entry was not decoded properly")
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
nginx-0.1.0:
|
||||
url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
|
||||
name: nginx
|
||||
description: string
|
||||
version: 0.1.0
|
||||
home: https://github.com/something
|
||||
keywords:
|
||||
- popular
|
||||
- web server
|
||||
- proxy
|
||||
alpine-1.0.0:
|
||||
url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
|
||||
name: alpine
|
||||
description: string
|
||||
version: 1.0.0
|
||||
home: https://github.com/something
|
||||
keywords:
|
||||
- linux
|
||||
- alpine
|
||||
- small
|
||||
- sumtin
|
||||
|
Loading…
Reference in new issue