ref(helm): refactor test index files for search

pull/745/head
Michelle Noorali 9 years ago
parent 2234dc8927
commit 0783fee7b7

@ -1,9 +1,9 @@
package main package main
import ( import (
"github.com/kubernetes/helm/pkg/repo"
"testing" "testing"
"github.com/kubernetes/helm/pkg/repo"
) )
const testDir = "testdata/" const testDir = "testdata/"

@ -1,5 +1,8 @@
foobar-0.1.0: foobar-0.1.0:
url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
name: foobar
removed: false
chartfile:
name: foobar name: foobar
description: string description: string
version: 0.1.0 version: 0.1.0
@ -9,6 +12,9 @@ foobar-0.1.0:
- hokey - hokey
oddness-1.2.3: oddness-1.2.3:
url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
name: oddness
removed: false
chartfile:
name: oddness name: oddness
description: string description: string
version: 1.2.3 version: 1.2.3

@ -1,5 +1,8 @@
nginx-0.1.0: nginx-0.1.0:
url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz url: http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
name: nginx
removed: false
chartfile:
name: nginx name: nginx
description: string description: string
version: 0.1.0 version: 0.1.0
@ -10,6 +13,9 @@ nginx-0.1.0:
- proxy - proxy
alpine-1.0.0: alpine-1.0.0:
url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz url: http://storage.googleapis.com/kubernetes-charts/alpine-1.0.0.tgz
name: alpine
removed: false
chartfile:
name: alpine name: alpine
description: string description: string
version: 1.0.0 version: 1.0.0

@ -12,6 +12,8 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
const testfile = "testdata/local-index.yaml"
var ( var (
testRepo = "test-repo" testRepo = "test-repo"
) )
@ -55,3 +57,37 @@ func TestDownloadIndexFile(t *testing.T) {
os.Remove(dirName) os.Remove(dirName)
} }
func TestLoadIndexFile(t *testing.T) {
cf, err := LoadIndexFile(testfile)
if err != nil {
t.Errorf("Failed to load index file: %s", err)
}
if len(cf.Entries) != 2 {
t.Errorf("Expected 2 entries in the index 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.Chartfile.Keywords) == 3 {
nginx = true
}
}
}
if k == "alpine-1.0.0" {
if e.Name == "alpine" {
if len(e.Chartfile.Keywords) == 4 {
alpine = true
}
}
}
}
if !nginx {
t.Errorf("nginx entry was not decoded properly")
}
if !alpine {
t.Errorf("alpine entry was not decoded properly")
}
}

@ -8,71 +8,10 @@ import (
"time" "time"
) )
const testfile = "testdata/local-index.yaml"
const testRepositoriesFile = "testdata/repositories.yaml" const testRepositoriesFile = "testdata/repositories.yaml"
const testRepository = "testdata/repository" const testRepository = "testdata/repository"
const testURL = "http://example-charts.com" const testURL = "http://example-charts.com"
func TestLoadIndexFile(t *testing.T) {
cf, err := LoadIndexFile(testfile)
if err != nil {
t.Errorf("Failed to load index file: %s", err)
}
if len(cf.Entries) != 2 {
t.Errorf("Expected 2 entries in the index 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.Chartfile.Keywords) == 3 {
nginx = true
}
}
}
if k == "alpine-1.0.0" {
if e.Name == "alpine" {
if len(e.Chartfile.Keywords) == 4 {
alpine = true
}
}
}
}
if !nginx {
t.Errorf("nginx entry was not decoded properly")
}
if !alpine {
t.Errorf("alpine entry was not decoded properly")
}
}
func TestLoadRepositoriesFile(t *testing.T) {
rf, err := LoadRepositoriesFile(testRepositoriesFile)
if err != nil {
t.Errorf(testRepositoriesFile + " could not be loaded: " + err.Error())
}
expected := map[string]string{"best-charts-ever": "http://best-charts-ever.com",
"okay-charts": "http://okay-charts.org", "example123": "http://examplecharts.net/charts/123"}
numOfRepositories := len(rf.Repositories)
expectedNumOfRepositories := 3
if numOfRepositories != expectedNumOfRepositories {
t.Errorf("Expected %v repositories but only got %v", expectedNumOfRepositories, numOfRepositories)
}
for expectedRepo, expectedURL := range expected {
actual, ok := rf.Repositories[expectedRepo]
if !ok {
t.Errorf("Expected repository: %v but was not found", expectedRepo)
}
if expectedURL != actual {
t.Errorf("Expected url %s for the %s repository but got %s ", expectedURL, expectedRepo, actual)
}
}
}
func TestLoadChartRepository(t *testing.T) { func TestLoadChartRepository(t *testing.T) {
cr, err := LoadChartRepository(testRepository, testURL) cr, err := LoadChartRepository(testRepository, testURL)
if err != nil { if err != nil {
@ -153,3 +92,29 @@ func TestIndex(t *testing.T) {
} }
} }
} }
func TestLoadRepositoriesFile(t *testing.T) {
rf, err := LoadRepositoriesFile(testRepositoriesFile)
if err != nil {
t.Errorf(testRepositoriesFile + " could not be loaded: " + err.Error())
}
expected := map[string]string{"best-charts-ever": "http://best-charts-ever.com",
"okay-charts": "http://okay-charts.org", "example123": "http://examplecharts.net/charts/123"}
numOfRepositories := len(rf.Repositories)
expectedNumOfRepositories := 3
if numOfRepositories != expectedNumOfRepositories {
t.Errorf("Expected %v repositories but only got %v", expectedNumOfRepositories, numOfRepositories)
}
for expectedRepo, expectedURL := range expected {
actual, ok := rf.Repositories[expectedRepo]
if !ok {
t.Errorf("Expected repository: %v but was not found", expectedRepo)
}
if expectedURL != actual {
t.Errorf("Expected url %s for the %s repository but got %s ", expectedURL, expectedRepo, actual)
}
}
}

Loading…
Cancel
Save