fix(repo): ensure index generates in the right order

pull/1412/head
Adnan Abdulhussein 8 years ago
parent 313a9dc4a3
commit ee7fe7c728

@ -94,5 +94,6 @@ func index(dir, url, mergeTo string) error {
}
i.Merge(i2)
}
i.SortEntries()
return i.WriteFile(out, 0755)
}

@ -38,6 +38,10 @@ func TestRepoIndexCmd(t *testing.T) {
if err := os.Link("testdata/testcharts/compressedchart-0.1.0.tgz", comp); err != nil {
t.Fatal(err)
}
comp2 := filepath.Join(dir, "compressedchart-0.2.0.tgz")
if err := os.Link("testdata/testcharts/compressedchart-0.2.0.tgz", comp2); err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(nil)
c := newRepoIndexCmd(buf)
@ -57,16 +61,32 @@ func TestRepoIndexCmd(t *testing.T) {
t.Errorf("expected 1 entry, got %d: %#v", len(index.Entries), index.Entries)
}
vs := index.Entries["compressedchart"]
if len(vs) != 2 {
t.Errorf("expected 2 versions, got %d: %#v", len(vs), vs)
}
expectedVersion := "0.2.0"
if vs[0].Version != expectedVersion {
t.Errorf("expected %q, got %q", expectedVersion, vs[0].Version)
}
// Test with `--merge`
// Remove first chart.
// Remove first two charts.
if err := os.Remove(comp); err != nil {
t.Fatal(err)
}
// Add another chart.
if err := os.Remove(comp2); err != nil {
t.Fatal(err)
}
// Add a new chart and a new version of an existing chart
if err := os.Link("testdata/testcharts/reqtest-0.1.0.tgz", filepath.Join(dir, "reqtest-0.1.0.tgz")); err != nil {
t.Fatal(err)
}
if err := os.Link("testdata/testcharts/compressedchart-0.3.0.tgz", filepath.Join(dir, "compressedchart-0.3.0.tgz")); err != nil {
t.Fatal(err)
}
c.ParseFlags([]string{"--merge", destIndex})
if err := c.RunE(c, []string{dir}); err != nil {
@ -79,6 +99,16 @@ func TestRepoIndexCmd(t *testing.T) {
}
if len(index.Entries) != 2 {
t.Errorf("expected 2 entry, got %d: %#v", len(index.Entries), index.Entries)
t.Errorf("expected 2 entries, got %d: %#v", len(index.Entries), index.Entries)
}
vs = index.Entries["compressedchart"]
if len(vs) != 3 {
t.Errorf("expected 3 versions, got %d: %#v", len(vs), vs)
}
expectedVersion = "0.3.0"
if vs[0].Version != expectedVersion {
t.Errorf("expected %q, got %q", expectedVersion, vs[0].Version)
}
}

@ -95,6 +95,7 @@ func NewIndexFile() *IndexFile {
}
// Add adds a file to the index
// This can leave the index in an unsorted state
func (i IndexFile) Add(md *chart.Metadata, filename, baseURL, digest string) {
u := filename
if baseURL != "" {
@ -176,6 +177,8 @@ func (i IndexFile) WriteFile(dest string, mode os.FileMode) error {
//
// If one of the entries in the given index does _not_ already exist, it is added.
// In all other cases, the existing record is preserved.
//
// This can leave the index in an unsorted state
func (i *IndexFile) Merge(f *IndexFile) {
for _, cvs := range f.Entries {
for _, cv := range cvs {
@ -202,7 +205,7 @@ type ChartVersion struct {
//
// It indexes only charts that have been packaged (*.tgz).
//
// It writes the results to dir/index.yaml.
// The index returned will be in an unsorted state
func IndexDirectory(dir, baseURL string) (*IndexFile, error) {
archives, err := filepath.Glob(filepath.Join(dir, "*.tgz"))
if err != nil {

@ -197,12 +197,12 @@ func verifyLocalIndex(t *testing.T, i *IndexFile) {
Metadata: &chart.Metadata{
Name: "nginx",
Description: "string",
Version: "0.1.0",
Version: "0.2.0",
Keywords: []string{"popular", "web server", "proxy"},
Home: "https://github.com/something",
Home: "https://github.com/something/else",
},
URLs: []string{
"http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz",
"http://storage.googleapis.com/kubernetes-charts/nginx-0.2.0.tgz",
},
Digest: "sha256:1234567890abcdef",
},
@ -210,12 +210,12 @@ func verifyLocalIndex(t *testing.T, i *IndexFile) {
Metadata: &chart.Metadata{
Name: "nginx",
Description: "string",
Version: "0.2.0",
Version: "0.1.0",
Keywords: []string{"popular", "web server", "proxy"},
Home: "https://github.com/something/else",
Home: "https://github.com/something",
},
URLs: []string{
"http://storage.googleapis.com/kubernetes-charts/nginx-0.2.0.tgz",
"http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz",
},
Digest: "sha256:1234567890abcdef",
},

@ -133,7 +133,7 @@ func TestLoadChartRepository(t *testing.T) {
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")}
paths := []string{filepath.Join(testRepository, "frobnitz-1.2.3.tgz"), filepath.Join(testRepository, "sprocket-1.1.0.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)
@ -211,6 +211,12 @@ func verifyIndex(t *testing.T, actual *IndexFile) {
Version: "1.2.0",
},
},
{
Metadata: &chart.Metadata{
Name: "sprocket",
Version: "1.1.0",
},
},
},
}

@ -2,22 +2,22 @@ apiVersion: v1
entries:
nginx:
- urls:
- http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
- http://storage.googleapis.com/kubernetes-charts/nginx-0.2.0.tgz
name: nginx
description: string
version: 0.1.0
home: https://github.com/something
version: 0.2.0
home: https://github.com/something/else
digest: "sha256:1234567890abcdef"
keywords:
- popular
- web server
- proxy
- urls:
- http://storage.googleapis.com/kubernetes-charts/nginx-0.2.0.tgz
- http://storage.googleapis.com/kubernetes-charts/nginx-0.1.0.tgz
name: nginx
description: string
version: 0.2.0
home: https://github.com/something/else
version: 0.1.0
home: https://github.com/something
digest: "sha256:1234567890abcdef"
keywords:
- popular

Binary file not shown.
Loading…
Cancel
Save