mirror of https://github.com/helm/helm
Merge pull request #745 from michelleN/repo-index
feat(helm): generate index file in given directory with given urlpull/754/head
commit
7c2682112f
@ -1,18 +1,24 @@
|
|||||||
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
|
name: foobar
|
||||||
description: string
|
removed: false
|
||||||
version: 0.1.0
|
chartfile:
|
||||||
home: https://github.com/foo
|
name: foobar
|
||||||
keywords:
|
description: string
|
||||||
- dummy
|
version: 0.1.0
|
||||||
- hokey
|
home: https://github.com/foo
|
||||||
|
keywords:
|
||||||
|
- dummy
|
||||||
|
- 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
|
name: oddness
|
||||||
description: string
|
removed: false
|
||||||
version: 1.2.3
|
chartfile:
|
||||||
home: https://github.com/something
|
name: oddness
|
||||||
keywords:
|
description: string
|
||||||
- duck
|
version: 1.2.3
|
||||||
- sumtin
|
home: https://github.com/something
|
||||||
|
keywords:
|
||||||
|
- duck
|
||||||
|
- sumtin
|
||||||
|
@ -1,22 +1,28 @@
|
|||||||
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
|
name: nginx
|
||||||
description: string
|
removed: false
|
||||||
version: 0.1.0
|
chartfile:
|
||||||
home: https://github.com/something
|
name: nginx
|
||||||
keywords:
|
description: string
|
||||||
- popular
|
version: 0.1.0
|
||||||
- web server
|
home: https://github.com/something
|
||||||
- proxy
|
keywords:
|
||||||
|
- popular
|
||||||
|
- web server
|
||||||
|
- 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
|
name: alpine
|
||||||
description: string
|
removed: false
|
||||||
version: 1.0.0
|
chartfile:
|
||||||
home: https://github.com/something
|
name: alpine
|
||||||
keywords:
|
description: string
|
||||||
- linux
|
version: 1.0.0
|
||||||
- alpine
|
home: https://github.com/something
|
||||||
- small
|
keywords:
|
||||||
- sumtin
|
- linux
|
||||||
|
- alpine
|
||||||
|
- small
|
||||||
|
- sumtin
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package repo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
const testfile = "testdata/local-index.yaml"
|
|
||||||
|
|
||||||
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.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,120 @@
|
|||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testRepositoriesFile = "testdata/repositories.yaml"
|
||||||
|
const testRepository = "testdata/repository"
|
||||||
|
const testURL = "http://example-charts.com"
|
||||||
|
|
||||||
|
func TestLoadChartRepository(t *testing.T) {
|
||||||
|
cr, err := LoadChartRepository(testRepository, testURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
paths := []string{filepath.Join(testRepository, "frobnitz-1.2.3.tgz"), filepath.Join(testRepository, "sprocket-1.2.0.tgz")}
|
||||||
|
|
||||||
|
if cr.RootPath != testRepository {
|
||||||
|
t.Errorf("Expected %s as RootPath but got %s", testRepository, cr.RootPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(cr.ChartPaths, paths) {
|
||||||
|
t.Errorf("Expected %#v but got %#v\n", paths, cr.ChartPaths)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cr.URL != testURL {
|
||||||
|
t.Errorf("Expected url for chart repository to be %s but got %s", testURL, cr.URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIndex(t *testing.T) {
|
||||||
|
cr, err := LoadChartRepository(testRepository, testURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cr.Index()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error performing index: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tempIndexPath := filepath.Join(testRepository, indexPath)
|
||||||
|
actual, err := LoadIndexFile(tempIndexPath)
|
||||||
|
defer os.Remove(tempIndexPath) // clean up
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error loading index file %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
entries := actual.Entries
|
||||||
|
numEntries := len(entries)
|
||||||
|
if numEntries != 2 {
|
||||||
|
t.Errorf("Expected 2 charts to be listed in index file but got %v", numEntries)
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamps := make(map[string]string)
|
||||||
|
var empty time.Time
|
||||||
|
for chartName, details := range entries {
|
||||||
|
if details == nil {
|
||||||
|
t.Errorf("Chart Entry is not filled out for %s", chartName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if details.Created == empty.String() {
|
||||||
|
t.Errorf("Created timestamp under %s chart entry is nil", chartName)
|
||||||
|
}
|
||||||
|
timestamps[chartName] = details.Created
|
||||||
|
|
||||||
|
if details.Digest == "" {
|
||||||
|
t.Errorf("Digest was not set for %s", chartName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = cr.Index(); err != nil {
|
||||||
|
t.Errorf("Error performing index the second time: %v\n", err)
|
||||||
|
}
|
||||||
|
second, err := LoadIndexFile(tempIndexPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error loading index file second time: %#v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for chart, created := range timestamps {
|
||||||
|
v, ok := second.Entries[chart]
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("Expected %s chart entry in index file but did not find it", chart)
|
||||||
|
}
|
||||||
|
if v.Created != created {
|
||||||
|
t.Errorf("Expected Created timestamp to be %s, but got %s for chart %s", created, v.Created, chart)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,26 @@
|
|||||||
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
|
name: nginx
|
||||||
description: string
|
chartfile:
|
||||||
version: 0.1.0
|
name: nginx
|
||||||
home: https://github.com/something
|
description: string
|
||||||
keywords:
|
version: 0.1.0
|
||||||
- popular
|
home: https://github.com/something
|
||||||
- web server
|
keywords:
|
||||||
- proxy
|
- popular
|
||||||
|
- web server
|
||||||
|
- 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
|
name: alpine
|
||||||
description: string
|
chartfile:
|
||||||
version: 1.0.0
|
name: alpine
|
||||||
home: https://github.com/something
|
description: string
|
||||||
keywords:
|
version: 1.0.0
|
||||||
- linux
|
home: https://github.com/something
|
||||||
- alpine
|
keywords:
|
||||||
- small
|
- linux
|
||||||
- sumtin
|
- alpine
|
||||||
|
- small
|
||||||
|
- sumtin
|
||||||
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
best-charts-ever: http://best-charts-ever.com
|
||||||
|
okay-charts: http://okay-charts.org
|
||||||
|
example123: http://examplecharts.net/charts/123
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue