-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix(limit): limit release history number * fix * change variable name * add a test case * add two test cases * fix lint * tweak comments * tweak code * tweak comments Co-authored-by: Lisheng Zheng <[email protected]> Co-authored-by: Lisheng Zheng <[email protected]>
- Loading branch information
Showing
5 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package gc | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
releaseapi "github.com/caicloud/clientset/pkg/apis/release/v1alpha1" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func newRelease(name string, version int32) *releaseapi.Release { | ||
return &releaseapi.Release{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
Status: releaseapi.ReleaseStatus{ | ||
Version: version, | ||
}, | ||
} | ||
} | ||
|
||
func TestIsRetainHistory(t *testing.T) { | ||
gc := &GarbageCollector{ | ||
historyLimit: 5, | ||
} | ||
testCases := []struct { | ||
rls string | ||
curVersion int32 | ||
rlsHistory string | ||
want bool | ||
err error | ||
}{ | ||
{"hello", 3, "hello-v1", true, nil}, | ||
{"hello", 10, "hello-v1", false, nil}, | ||
{"hello", 3, "hello-v0", false, fmt.Errorf("cur release history hello-v0 version 0 is invalid")}, | ||
{"hello", 3, "hello-v-9", false, fmt.Errorf("cur release history hello-v-9 version -9 is invalid")}, | ||
{"hello", 10, "hello-v5", false, nil}, | ||
{"hello", 10, "hello-v6", true, nil}, | ||
{"hello", 10, "hello1-v6", false, nil}, | ||
{"hello", 10, "hello-v20", true, nil}, | ||
{"hello", 10, "hello1-v20", false, nil}, | ||
} | ||
|
||
for _, ca := range testCases { | ||
get, err := gc.ifRetainHistory(newRelease(ca.rls, ca.curVersion), ca.rlsHistory) | ||
if reflect.DeepEqual(err, ca.want) || get != ca.want { | ||
t.Errorf("limit %v got %v but condition is %v err %v", gc.historyLimit, get, ca, err) | ||
} | ||
} | ||
} |