mirror of
https://github.com/fluxcd/flagger.git
synced 2026-03-02 17:51:00 +00:00
add e2e tests istio clean up comment from review add e2e tests istio clean up comment from review clean up logging statement add e2e tests istio clean up comment from review clean up logging statement add log statement on e2e iteration add e2e tests istio clean up comment from review clean up logging statement add log statement on e2e iteration extend timeout for finalizing add e2e tests istio clean up comment from review clean up logging statement add log statement on e2e iteration extend timeout for finalizing add phase to kustomize crd add e2e tests istio clean up comment from review clean up logging statement add log statement on e2e iteration extend timeout for finalizing add phase to kustomize crd revert timeout on circleci vs and svc checks for istio e2e tests fix fmt errors and tests add get statement in e2e test add get statement in e2e test add namespace to e2e use only selector for service revert
115 lines
3.1 KiB
Go
115 lines
3.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1beta1"
|
|
fakeFlagger "github.com/weaveworks/flagger/pkg/client/clientset/versioned/fake"
|
|
"github.com/weaveworks/flagger/pkg/logger"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
k8sTesting "k8s.io/client-go/testing"
|
|
|
|
"testing"
|
|
)
|
|
|
|
//Test has finalizers
|
|
func TestFinalizer_hasFinalizer(t *testing.T) {
|
|
|
|
withFinalizer := newDeploymentTestCanary()
|
|
withFinalizer.Finalizers = append(withFinalizer.Finalizers, finalizer)
|
|
|
|
tables := []struct {
|
|
canary *flaggerv1.Canary
|
|
result bool
|
|
}{
|
|
{newDeploymentTestCanary(), false},
|
|
{withFinalizer, true},
|
|
}
|
|
|
|
for _, table := range tables {
|
|
isPresent := hasFinalizer(table.canary, finalizer)
|
|
if isPresent != table.result {
|
|
t.Errorf("Result of hasFinalizer returned [%t], but expected [%t]", isPresent, table.result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFinalizer_addFinalizer(t *testing.T) {
|
|
|
|
mockError := fmt.Errorf("failed to add finalizer to canary %s", "testCanary")
|
|
cs := fakeFlagger.NewSimpleClientset(newDeploymentTestCanary())
|
|
//prepend so it is evaluated over the catch all *
|
|
cs.PrependReactor("update", "canaries", func(action k8sTesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
return true, nil, mockError
|
|
})
|
|
|
|
logger, _ := logger.NewLogger("debug")
|
|
m := fixture{
|
|
canary: newDeploymentTestCanary(),
|
|
flaggerClient: cs,
|
|
ctrl: &Controller{
|
|
flaggerClient: cs,
|
|
logger: logger,
|
|
},
|
|
logger: logger,
|
|
}
|
|
|
|
tables := []struct {
|
|
mock fixture
|
|
canary *flaggerv1.Canary
|
|
error error
|
|
}{
|
|
{newDeploymentFixture(nil), newDeploymentTestCanary(), nil},
|
|
{m, m.canary, mockError},
|
|
}
|
|
|
|
for _, table := range tables {
|
|
response := table.mock.ctrl.addFinalizer(table.canary, finalizer)
|
|
|
|
if table.error != nil && response == nil {
|
|
t.Errorf("Expected an error from addFinalizer, but wasn't present")
|
|
} else if table.error == nil && response != nil {
|
|
t.Errorf("Expected no error from addFinalizer, but returned error %s", response)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func TestFinalizer_removeFinalizer(t *testing.T) {
|
|
|
|
withFinalizer := newDeploymentTestCanary()
|
|
withFinalizer.Finalizers = append(withFinalizer.Finalizers, finalizer)
|
|
|
|
mockError := fmt.Errorf("failed to add finalizer to canary %s", "testCanary")
|
|
cs := fakeFlagger.NewSimpleClientset(newDeploymentTestCanary())
|
|
//prepend so it is evaluated over the catch all *
|
|
cs.PrependReactor("update", "canaries", func(action k8sTesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
return true, nil, mockError
|
|
})
|
|
m := fixture{
|
|
canary: withFinalizer,
|
|
flaggerClient: cs,
|
|
ctrl: &Controller{flaggerClient: cs},
|
|
}
|
|
|
|
tables := []struct {
|
|
mock fixture
|
|
canary *flaggerv1.Canary
|
|
error error
|
|
}{
|
|
{newDeploymentFixture(nil), withFinalizer, nil},
|
|
{m, m.canary, mockError},
|
|
}
|
|
|
|
for _, table := range tables {
|
|
response := table.mock.ctrl.removeFinalizer(table.canary, finalizer)
|
|
|
|
if table.error != nil && response == nil {
|
|
t.Errorf("Expected an error from addFinalizer, but wasn't present")
|
|
} else if table.error == nil && response != nil {
|
|
t.Errorf("Expected no error from addFinalizer, but returned error %s", response)
|
|
}
|
|
|
|
}
|
|
}
|