From 0783fee7b7d8f6afde9baa511319ecf9d72b9de3 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Fri, 20 May 2016 14:28:58 -0400 Subject: [PATCH] ref(helm): refactor test index files for search --- cmd/helm/search_test.go | 4 +- cmd/helm/testdata/foobar-index.yaml | 30 ++++++---- cmd/helm/testdata/local-index.yaml | 36 +++++++----- pkg/repo/index_test.go | 36 ++++++++++++ pkg/repo/repo_test.go | 87 +++++++++-------------------- 5 files changed, 103 insertions(+), 90 deletions(-) diff --git a/cmd/helm/search_test.go b/cmd/helm/search_test.go index 7001cdec3..5a54bc70d 100644 --- a/cmd/helm/search_test.go +++ b/cmd/helm/search_test.go @@ -1,9 +1,9 @@ package main import ( - "github.com/kubernetes/helm/pkg/repo" - "testing" + + "github.com/kubernetes/helm/pkg/repo" ) const testDir = "testdata/" diff --git a/cmd/helm/testdata/foobar-index.yaml b/cmd/helm/testdata/foobar-index.yaml index ef28fdc48..c23e5ea0c 100644 --- a/cmd/helm/testdata/foobar-index.yaml +++ b/cmd/helm/testdata/foobar-index.yaml @@ -1,18 +1,24 @@ 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 + removed: false + chartfile: + 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 + removed: false + chartfile: + name: oddness + description: string + version: 1.2.3 + home: https://github.com/something + keywords: + - duck + - sumtin diff --git a/cmd/helm/testdata/local-index.yaml b/cmd/helm/testdata/local-index.yaml index 9d8d0e5e4..efaf5e46e 100644 --- a/cmd/helm/testdata/local-index.yaml +++ b/cmd/helm/testdata/local-index.yaml @@ -1,22 +1,28 @@ 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 + removed: false + chartfile: + 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 + removed: false + chartfile: + name: alpine + description: string + version: 1.0.0 + home: https://github.com/something + keywords: + - linux + - alpine + - small + - sumtin diff --git a/pkg/repo/index_test.go b/pkg/repo/index_test.go index 0b5590c96..e891c8690 100644 --- a/pkg/repo/index_test.go +++ b/pkg/repo/index_test.go @@ -12,6 +12,8 @@ import ( "gopkg.in/yaml.v2" ) +const testfile = "testdata/local-index.yaml" + var ( testRepo = "test-repo" ) @@ -55,3 +57,37 @@ func TestDownloadIndexFile(t *testing.T) { 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") + } +} diff --git a/pkg/repo/repo_test.go b/pkg/repo/repo_test.go index 1ad181813..3680691c5 100644 --- a/pkg/repo/repo_test.go +++ b/pkg/repo/repo_test.go @@ -8,71 +8,10 @@ import ( "time" ) -const testfile = "testdata/local-index.yaml" const testRepositoriesFile = "testdata/repositories.yaml" const testRepository = "testdata/repository" 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) { cr, err := LoadChartRepository(testRepository, testURL) 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) + } + } +}