Commit 2234dc89 authored by Michelle Noorali's avatar Michelle Noorali

feat(helm): handle update case on index function

parent 7bd739c2
...@@ -115,6 +115,7 @@ func (r *ChartRepository) Index() error { ...@@ -115,6 +115,7 @@ func (r *ChartRepository) Index() error {
if err != nil { if err != nil {
return err return err
} }
chartfile := ch.Chartfile() chartfile := ch.Chartfile()
hash, err := generateDigest(path) hash, err := generateDigest(path)
if err != nil { if err != nil {
...@@ -126,7 +127,15 @@ func (r *ChartRepository) Index() error { ...@@ -126,7 +127,15 @@ func (r *ChartRepository) Index() error {
r.IndexFile.Entries = make(map[string]*ChartRef) r.IndexFile.Entries = make(map[string]*ChartRef)
} }
entry := &ChartRef{Chartfile: *chartfile, Name: chartfile.Name, URL: r.URL, Created: time.Now().UTC().String(), Digest: hash, Removed: false} ref, ok := r.IndexFile.Entries[key]
var created string
if ok && ref.Created != "" {
created = ref.Created
} else {
created = time.Now().UTC().String()
}
entry := &ChartRef{Chartfile: *chartfile, Name: chartfile.Name, URL: r.URL, Created: created, Digest: hash, Removed: false}
r.IndexFile.Entries[key] = entry r.IndexFile.Entries[key] = entry
......
...@@ -107,6 +107,7 @@ func TestIndex(t *testing.T) { ...@@ -107,6 +107,7 @@ func TestIndex(t *testing.T) {
tempIndexPath := filepath.Join(testRepository, indexPath) tempIndexPath := filepath.Join(testRepository, indexPath)
actual, err := LoadIndexFile(tempIndexPath) actual, err := LoadIndexFile(tempIndexPath)
defer os.Remove(tempIndexPath) // clean up
if err != nil { if err != nil {
t.Errorf("Error loading index file %v", err) t.Errorf("Error loading index file %v", err)
} }
...@@ -117,6 +118,7 @@ func TestIndex(t *testing.T) { ...@@ -117,6 +118,7 @@ func TestIndex(t *testing.T) {
t.Errorf("Expected 2 charts to be listed in index file but got %v", numEntries) t.Errorf("Expected 2 charts to be listed in index file but got %v", numEntries)
} }
timestamps := make(map[string]string)
var empty time.Time var empty time.Time
for chartName, details := range entries { for chartName, details := range entries {
if details == nil { if details == nil {
...@@ -126,13 +128,28 @@ func TestIndex(t *testing.T) { ...@@ -126,13 +128,28 @@ func TestIndex(t *testing.T) {
if details.Created == empty.String() { if details.Created == empty.String() {
t.Errorf("Created timestamp under %s chart entry is nil", chartName) t.Errorf("Created timestamp under %s chart entry is nil", chartName)
} }
timestamps[chartName] = details.Created
if details.Digest == "" { if details.Digest == "" {
t.Errorf("Digest was not set for %s", chartName) t.Errorf("Digest was not set for %s", chartName)
} }
} }
//TODO: test update case 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)
}
os.Remove(tempIndexPath) // clean up 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)
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment