Commit ff3dc9dd authored by Arash Deshmeh's avatar Arash Deshmeh

fix(helm): fix unit tests of the history command to ensure the max option is…

fix(helm): fix unit tests of the history command to ensure the max option is covered. Add the required support to the fake client
Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>
parent a05311e6
......@@ -63,7 +63,7 @@ func TestHistoryCmd(t *testing.T) {
name: "get history with max limit set",
args: []string{"angry-bird"},
flags: []string{"--max", "2"},
rels: releases[:2],
rels: releases,
expected: "REVISION\tUPDATED \tSTATUS \tCHART \tAPP VERSION\tDESCRIPTION \n3 \t(.*)\tSUPERSEDED\tfoo-0.1.0-beta.1\t1.3 \tRelease mock\n4 \t(.*)\tDEPLOYED \tfoo-0.1.0-beta.1\t1.4 \tRelease mock\n",
},
{
......
......@@ -229,7 +229,22 @@ func (c *FakeClient) ReleaseContent(rlsName string, opts ...ContentOption) (resp
// ReleaseHistory returns a release's revision history.
func (c *FakeClient) ReleaseHistory(rlsName string, opts ...HistoryOption) (*rls.GetHistoryResponse, error) {
return &rls.GetHistoryResponse{Releases: c.Rels}, nil
reqOpts := c.Opts
for _, opt := range opts {
opt(&reqOpts)
}
maxLen := int(reqOpts.histReq.Max)
var resp rls.GetHistoryResponse
for _, rel := range c.Rels {
if maxLen > 0 && len(resp.Releases) >= maxLen {
return &resp, nil
}
if rel.Name == rlsName {
resp.Releases = append(resp.Releases, rel)
}
}
return &resp, nil
}
// RunReleaseTest executes a pre-defined tests on a release
......
......@@ -446,3 +446,75 @@ func TestFakeClient_UpdateReleaseFromChart(t *testing.T) {
})
}
}
func TestFakeClient_ReleaseHistory(t *testing.T) {
relName := "angry-dolphin"
rels := []*release.Release{
ReleaseMock(&MockReleaseOptions{Name: relName, Version: 1}),
ReleaseMock(&MockReleaseOptions{Name: relName, Version: 2}),
ReleaseMock(&MockReleaseOptions{Name: relName, Version: 3}),
ReleaseMock(&MockReleaseOptions{Name: relName, Version: 4}),
}
type fields struct {
Rels []*release.Release
}
type args struct {
rlsName string
opts []HistoryOption
}
tests := []struct {
name string
fields fields
args args
want *rls.GetHistoryResponse
wantErr bool
}{
{
name: "Get all revisions of a release",
fields: fields{
Rels: rels,
},
args: args{
rlsName: relName,
opts: nil,
},
want: &rls.GetHistoryResponse{
Releases: rels,
},
wantErr: false,
},
{
name: "Get only 2 revisions of a release",
fields: fields{
Rels: rels,
},
args: args{
rlsName: relName,
opts: []HistoryOption{
WithMaxHistory(2),
},
},
want: &rls.GetHistoryResponse{
Releases: rels[:2],
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &FakeClient{
Rels: tt.fields.Rels,
}
got, err := c.ReleaseHistory(tt.args.rlsName, tt.args.opts...)
if (err != nil) != tt.wantErr {
t.Errorf("FakeClient.ReleaseHistory() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("FakeClient.ReleaseHistory() = %v, want %v", got, tt.want)
}
})
}
}
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