From 839f22226c85a848112e98801c70804a01be49d3 Mon Sep 17 00:00:00 2001 From: Adnan Abdulhussein Date: Tue, 18 Oct 2016 18:04:36 -0700 Subject: [PATCH] fix(repo): ensure index generates in the right order --- pkg/repo/index.go | 1 + pkg/repo/index_test.go | 24 +++++++++++++----- pkg/repo/repo_test.go | 8 +++++- pkg/repo/testdata/local-index.yaml | 12 ++++----- .../testdata/repository/sprocket-1.1.0.tgz | Bin 0 -> 814 bytes 5 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 pkg/repo/testdata/repository/sprocket-1.1.0.tgz diff --git a/pkg/repo/index.go b/pkg/repo/index.go index 2b066d47c..3b2737bfe 100644 --- a/pkg/repo/index.go +++ b/pkg/repo/index.go @@ -222,6 +222,7 @@ func IndexDirectory(dir, baseURL string) (*IndexFile, error) { } index.Add(c.Metadata, fname, baseURL, hash) } + index.SortEntries() return index, nil } diff --git a/pkg/repo/index_test.go b/pkg/repo/index_test.go index 6e61b4dc2..efdda7202 100644 --- a/pkg/repo/index_test.go +++ b/pkg/repo/index_test.go @@ -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", }, @@ -282,6 +282,18 @@ func TestIndexDirectory(t *testing.T) { if frob.Name != "frobnitz" { t.Errorf("Expected frobnitz, got %q", frob.Name) } + + cname = "sprocket" + sprocket, ok := index.Entries[cname] + if !ok { + t.Fatalf("Could not read chart %s", cname) + } + + sproc := sprocket[0] + expectedVersion := "1.2.0" + if sproc.Version != expectedVersion { + t.Errorf("Expected %q, got %q", expectedVersion, sproc.Version) + } } func TestLoadUnversionedIndex(t *testing.T) { diff --git a/pkg/repo/repo_test.go b/pkg/repo/repo_test.go index 0f4589dba..704c3fe3d 100644 --- a/pkg/repo/repo_test.go +++ b/pkg/repo/repo_test.go @@ -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", + }, + }, }, } diff --git a/pkg/repo/testdata/local-index.yaml b/pkg/repo/testdata/local-index.yaml index ae29dfd8f..c0682643b 100644 --- a/pkg/repo/testdata/local-index.yaml +++ b/pkg/repo/testdata/local-index.yaml @@ -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 diff --git a/pkg/repo/testdata/repository/sprocket-1.1.0.tgz b/pkg/repo/testdata/repository/sprocket-1.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..595e9cc0397068b278d521615b97ae3319eb3623 GIT binary patch literal 814 zcmV+}1JV2+iwG0|32ul0|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PNe%ZqrH>2k_HMcVp?+SNGlrnCmX9_#`X6H(&v8fb67B6ZK<3NLo0*jqRyDvFrY4I*N|Y zl?;byygM;h#vSogz@quS?|0hmYU}&{{MK)^ck2DBJ!p1<7O;ii$axBFxB}n*(SGJ1 z?uLj^hbqZUBC{^rj}y%j%{V*#vv90frr2e%F?rYX@EK2Yfo>>MYlx#GsUqFA8mzBm zFH6jGt5IKRHCQAg9$6_*GQ*P$Rdp(+JP}FUt}H*kGx)xYiQr_TQ&7X|8{G5}na|De^G%YQ4_ z-l6<2!zSBh<5$o6i9i<0Dy+KP=_i9i@p5QzC%JOUtg(kYMaR+@R-;CpL#J$KNmdRY z4~3BI_}Hz&`+`N-=Y=rL zIg(05&dCWy_?K4a-<>W1Tz!-;@-r^ae`|Iu7|;Lh9h(1_qUS%k|A2Me?egF+0P%14 z>8;&^^{uY}X%faL1ZGkyE|LrTNGB(_LWca3DdXi_hu%PjGD1(Q&>JKsE_&tv_1>`P zp~|qFipo`jmk$S?!d!X=wTZal)saq&R3mR0>sLZAeyo6djipT8fk z`mP8egb+dqAxmWPHFyO8>yu-9vR#|o5<&`)b5x|=bfG->4@BdHN|KDtY zPd30u8{mTt@ZJV^X9K*o0bbhxhc>{04RFr}*s=jOZGb=QaX+6oR{T(e5JCtcgb+f0 zGqc637nQO?qiWQ%tzKVBug4W=S*Q@Zz%H&ug~mCxsM8DPi(Tu}XNq0nY^5wr%4cC( sQ47;LTd0d~;Y@{V)Ag^c=Y`n<*;T(FLdXhz4*&rF|3}zP2LM6<0Noys