Skip to content

Commit f8f4238

Browse files
committed
fixed some cmd precedents and added tests
1 parent f80cf30 commit f8f4238

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

cmd/hauler/cli/store/add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ func resolveChartJobs(o *flags.SyncOpts, annotations map[string]string, manifest
821821
if caFile == "" {
822822
if ch.CaFile != "" {
823823
caFile = ch.CaFile
824-
} else if annotations[consts.ImageAnnotationCaFile] == "true" {
824+
} else if annotations[consts.ImageAnnotationCaFile] != "" {
825825
caFile = annotations[consts.ImageAnnotationCaFile]
826826
}
827827
}

cmd/hauler/cli/store/add_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,39 @@ func TestResolveChartJobs_CredentialFields(t *testing.T) {
22202220
}
22212221
}
22222222

2223+
func TestResolveChartJobs_CaFilePrecedence(t *testing.T) {
2224+
tests := []struct {
2225+
name string
2226+
cli string
2227+
annotation string
2228+
perChart string
2229+
want string
2230+
}{
2231+
{name: "annotation used when CLI and per-chart unset", annotation: "/ann/ca.crt", want: "/ann/ca.crt"},
2232+
{name: "per-chart wins over annotation", annotation: "/ann/ca.crt", perChart: "/chart/ca.crt", want: "/chart/ca.crt"},
2233+
{name: "CLI wins over per-chart and annotation", cli: "/cli/ca.crt", annotation: "/ann/ca.crt", perChart: "/chart/ca.crt", want: "/cli/ca.crt"},
2234+
{name: "none set stays empty", want: ""},
2235+
}
2236+
2237+
for _, tc := range tests {
2238+
t.Run(tc.name, func(t *testing.T) {
2239+
o := &flags.SyncOpts{CaFile: tc.cli}
2240+
a := map[string]string{}
2241+
if tc.annotation != "" {
2242+
a[consts.ImageAnnotationCaFile] = tc.annotation
2243+
}
2244+
2245+
jobs, err := resolveChartJobs(o, a, "/manifests", []v1.Chart{{Name: "rancher", CaFile: tc.perChart}})
2246+
if err != nil {
2247+
t.Fatalf("resolveChartJobs: %v", err)
2248+
}
2249+
if got := jobs[0].opts.ChartOpts.CaFile; got != tc.want {
2250+
t.Errorf("CaFile = %q, want %q", got, tc.want)
2251+
}
2252+
})
2253+
}
2254+
}
2255+
22232256
// TestResolveChartJobs_CredentialEnv pins that UsernameEnv/PasswordEnv are
22242257
// resolved into ChartOpts.Username/Password via resolveChartCreds.
22252258
func TestResolveChartJobs_CredentialEnv(t *testing.T) {

0 commit comments

Comments
 (0)