Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order-dependency in test cases #364

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions pkg/backendconfig/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

var (
beConfig = &backendconfigv1beta1.BackendConfig{
defaultBeConfig = &backendconfigv1beta1.BackendConfig{
ObjectMeta: meta_v1.ObjectMeta{
Namespace: "default",
},
Expand All @@ -46,10 +46,12 @@ func TestValidateIAP(t *testing.T) {
testCases := []struct {
desc string
init func(kubeClient kubernetes.Interface)
beConfig *backendconfigv1beta1.BackendConfig
expectError bool
}{
{
desc: "secret does not exist",
desc: "secret does not exist",
beConfig: defaultBeConfig,
init: func(kubeClient kubernetes.Interface) {
secret := &v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand All @@ -62,7 +64,8 @@ func TestValidateIAP(t *testing.T) {
expectError: true,
},
{
desc: "secret does not contain client_id",
desc: "secret does not contain client_id",
beConfig: defaultBeConfig,
init: func(kubeClient kubernetes.Interface) {
secret := &v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand All @@ -78,7 +81,8 @@ func TestValidateIAP(t *testing.T) {
expectError: true,
},
{
desc: "secret does not contain client_secret",
desc: "secret does not contain client_secret",
beConfig: defaultBeConfig,
init: func(kubeClient kubernetes.Interface) {
secret := &v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand All @@ -94,7 +98,8 @@ func TestValidateIAP(t *testing.T) {
expectError: true,
},
{
desc: "validation passes",
desc: "validation passes",
beConfig: defaultBeConfig,
init: func(kubeClient kubernetes.Interface) {
secret := &v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Expand All @@ -112,13 +117,20 @@ func TestValidateIAP(t *testing.T) {
},
{
desc: "iap and cdn enabled at the same time",
beConfig: &backendconfigv1beta1.BackendConfig{
ObjectMeta: meta_v1.ObjectMeta{
Namespace: "default",
},
Spec: backendconfigv1beta1.BackendConfigSpec{
Iap: &backendconfigv1beta1.IAPConfig{
Enabled: true,
},
Cdn: &backendconfigv1beta1.CDNConfig{
Enabled: true,
},
},
},
init: func(kubeClient kubernetes.Interface) {
// TODO(rramkumar): Don't modify in-flight.
// This works now since this is the last test in the
// list of cases.
beConfig.Spec.Cdn = &backendconfigv1beta1.CDNConfig{
Enabled: true,
}
secret := &v1.Secret{
ObjectMeta: meta_v1.ObjectMeta{
Namespace: "default",
Expand All @@ -138,7 +150,7 @@ func TestValidateIAP(t *testing.T) {
for _, testCase := range testCases {
kubeClient := fake.NewSimpleClientset()
testCase.init(kubeClient)
err := Validate(kubeClient, beConfig)
err := Validate(kubeClient, testCase.beConfig)
if testCase.expectError && err == nil {
t.Errorf("%v: Expected error but got nil", testCase.desc)
}
Expand Down