Skip to content

Commit

Permalink
[#4739] Update e2e channel defaults webhook test (#4790)
Browse files Browse the repository at this point in the history
- 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 <vsameer@vmware.com>
  • Loading branch information
xtreme-sameer-vohra authored Jan 26, 2021
1 parent 88f397f commit 81ce898
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/e2e/channel_defaults_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -157,22 +158,22 @@ 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)
assert.Equal(t, eventingduck.BackoffPolicyExponential, *imc.Spec.Delivery.BackoffPolicy)

return true, nil
})
assert.Nil(t, err)
require.Nil(t, err)
}

func webhookObservedUpdate(ch *messagingv1.Channel) bool {
Expand Down

0 comments on commit 81ce898

Please sign in to comment.