From 81ce89802f863e368598fdbb51013f5745e4e9bd Mon Sep 17 00:00:00 2001 From: Sameer Vohra Date: Tue, 26 Jan 2021 05:09:30 -0600 Subject: [PATCH] [#4739] Update e2e channel defaults webhook test (#4790) - use "require.Nil" instead of "assert.Equal" for test setup and where we don't wish to retry. The latter notes a failure but doesn't fail immediately. This resulted in panics in subsequent sections of the broker defaults webhook test [#4717] and made it hard to pin point the reason. "require.Nil" will output the error and fail immediately making it easier to debug issues with test setup. Signed-off-by: Sameer Vohra --- test/e2e/channel_defaults_webhook_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/e2e/channel_defaults_webhook_test.go b/test/e2e/channel_defaults_webhook_test.go index 65688413dca..e306bb62bc3 100644 --- a/test/e2e/channel_defaults_webhook_test.go +++ b/test/e2e/channel_defaults_webhook_test.go @@ -26,6 +26,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -58,12 +59,12 @@ func TestChannelNamespaceDefaulting(t *testing.T) { t.Log("Updating defaulting ConfigMap") cm, err := c.Kube.CoreV1().ConfigMaps(system.Namespace()).Get(ctx, defaultChannelCM, metav1.GetOptions{}) - assert.Nil(t, err) + require.Nil(t, err) // Preserve existing namespace defaults. defaults := make(map[string]map[string]interface{}) err = yaml.Unmarshal([]byte(cm.Data[defaultChannelConfigKey]), &defaults) - assert.Nil(t, err) + require.Nil(t, err) defaults["namespaceDefaults"][c.Namespace] = map[string]interface{}{ "apiVersion": "messaging.knative.dev/v1", @@ -78,7 +79,7 @@ func TestChannelNamespaceDefaulting(t *testing.T) { } b, err := yaml.Marshal(defaults) - assert.Nil(t, err) + require.Nil(t, err) cm.Data[defaultChannelConfigKey] = string(b) @@ -96,7 +97,7 @@ func TestChannelNamespaceDefaulting(t *testing.T) { return nil }) - assert.Nil(t, err) + require.Nil(t, err) // Create a Channel and check whether it has the DeliverySpec set as we specified above. // Since the webhook receives the updates at some undetermined time after the update to reduce flakiness retry after @@ -133,11 +134,11 @@ func TestChannelNamespaceDefaulting(t *testing.T) { Resource(schema.GroupVersionResource{Group: "messaging.knative.dev", Version: "v1", Resource: "channels"}). Namespace(c.Namespace). Create(ctx, obj, metav1.CreateOptions{}) - assert.Nil(t, err) + require.Nil(t, err) channel := &messagingv1.Channel{} err = runtime.DefaultUnstructuredConverter.FromUnstructured(createdObj.Object, channel) - assert.Nil(t, err) + require.Nil(t, err) if !webhookObservedUpdate(channel) { return fmt.Errorf("webhook hasn't seen the update: %+v", channel) @@ -157,14 +158,14 @@ func TestChannelNamespaceDefaulting(t *testing.T) { return nil }) - assert.Nil(t, err) + require.Nil(t, err) err = wait.Poll(time.Second, time.Minute, func() (done bool, err error) { imc, err := c.Eventing.MessagingV1().InMemoryChannels(c.Namespace).Get(ctx, lastName, metav1.GetOptions{}) if apierrors.IsNotFound(err) { return false, nil } - assert.Nil(t, err) + require.Nil(t, err) assert.Equal(t, "PT0.5S", *imc.Spec.Delivery.BackoffDelay) assert.Equal(t, int32(5), *imc.Spec.Delivery.Retry) @@ -172,7 +173,7 @@ func TestChannelNamespaceDefaulting(t *testing.T) { return true, nil }) - assert.Nil(t, err) + require.Nil(t, err) } func webhookObservedUpdate(ch *messagingv1.Channel) bool {