Extend test SetupMocks() to take arbitrary Canary resources

SetupMocks() currently takes a bool switch that tells it to configure
against either a shifting canary or an A-B canary.  I'll need a third
canary that has mirroring turned on so I changed this to an interface
that just takes the canary to configure (and configs the default
shifting canary if you pass nil).
This commit is contained in:
Andrew Jenkins
2019-09-24 16:15:45 -06:00
parent 2e079ba7a1
commit 655df36913
2 changed files with 11 additions and 13 deletions
+3 -5
View File
@@ -42,11 +42,9 @@ type Mocks struct {
router router.Interface
}
func SetupMocks(abtest bool) Mocks {
// init canary
c := newTestCanary()
if abtest {
c = newTestCanaryAB()
func SetupMocks(c *v1alpha3.Canary) Mocks {
if c == nil {
c = newTestCanary()
}
flaggerClient := fakeFlagger.NewSimpleClientset(c)
+8 -8
View File
@@ -8,7 +8,7 @@ import (
)
func TestScheduler_Init(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
mocks.ctrl.advanceCanary("podinfo", "default", true)
_, err := mocks.kubeClient.AppsV1().Deployments("default").Get("podinfo-primary", metav1.GetOptions{})
@@ -18,7 +18,7 @@ func TestScheduler_Init(t *testing.T) {
}
func TestScheduler_NewRevision(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
mocks.ctrl.advanceCanary("podinfo", "default", true)
// update
@@ -42,7 +42,7 @@ func TestScheduler_NewRevision(t *testing.T) {
}
func TestScheduler_Rollback(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
// init
mocks.ctrl.advanceCanary("podinfo", "default", true)
@@ -66,7 +66,7 @@ func TestScheduler_Rollback(t *testing.T) {
}
func TestScheduler_SkipAnalysis(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
// init
mocks.ctrl.advanceCanary("podinfo", "default", true)
@@ -107,7 +107,7 @@ func TestScheduler_SkipAnalysis(t *testing.T) {
}
func TestScheduler_NewRevisionReset(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
// init
mocks.ctrl.advanceCanary("podinfo", "default", true)
@@ -169,7 +169,7 @@ func TestScheduler_NewRevisionReset(t *testing.T) {
}
func TestScheduler_Promotion(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
// init
mocks.ctrl.advanceCanary("podinfo", "default", true)
@@ -320,7 +320,7 @@ func TestScheduler_Promotion(t *testing.T) {
}
func TestScheduler_ABTesting(t *testing.T) {
mocks := SetupMocks(true)
mocks := SetupMocks(newTestCanaryAB())
// init
mocks.ctrl.advanceCanary("podinfo", "default", true)
@@ -408,7 +408,7 @@ func TestScheduler_ABTesting(t *testing.T) {
}
func TestScheduler_PortDiscovery(t *testing.T) {
mocks := SetupMocks(false)
mocks := SetupMocks(nil)
// enable port discovery
cd, err := mocks.flaggerClient.FlaggerV1alpha3().Canaries("default").Get("podinfo", metav1.GetOptions{})