diff --git a/pkg/ctl/namespace/clear_backlog_test.go b/pkg/ctl/namespace/clear_backlog_test.go index d54c5970..5e4440a8 100644 --- a/pkg/ctl/namespace/clear_backlog_test.go +++ b/pkg/ctl/namespace/clear_backlog_test.go @@ -72,10 +72,10 @@ func TestClearBacklogOnNonExistingNs(t *testing.T) { args := []string{"clear-backlog", "-f", "--bundle", "0xc0000000_0xffffffff", ns} _, execErr, _, _ := TestNamespaceCommands(ClearBacklogCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) args = []string{"clear-backlog", "-f", "--sub", "sub", "--bundle", "0xc0000000_0xffffffff", ns} _, execErr, _, _ = TestNamespaceCommands(ClearBacklogCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/compaction_threshold_test.go b/pkg/ctl/namespace/compaction_threshold_test.go index a8bb6e63..eff27952 100644 --- a/pkg/ctl/namespace/compaction_threshold_test.go +++ b/pkg/ctl/namespace/compaction_threshold_test.go @@ -58,7 +58,7 @@ func TestSetCompactionThresholdOnNonExistingNs(t *testing.T) { args := []string{"set-compaction-threshold", "--size", "10m", ns} _, execErr, _, _ := TestNamespaceCommands(SetCompactionThresholdCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestGetCompactionThresholdOnNonExistingNs(t *testing.T) { @@ -66,5 +66,5 @@ func TestGetCompactionThresholdOnNonExistingNs(t *testing.T) { args := []string{"get-compaction-threshold", ns} _, execErr, _, _ := TestNamespaceCommands(GetCompactionThresholdCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/dispatch_rate_test.go b/pkg/ctl/namespace/dispatch_rate_test.go index e827d157..6278efb4 100644 --- a/pkg/ctl/namespace/dispatch_rate_test.go +++ b/pkg/ctl/namespace/dispatch_rate_test.go @@ -112,5 +112,5 @@ func TestGetDispatchRateOnNonExistingNs(t *testing.T) { args := []string{"get-dispatch-rate", ns} _, execErr, _, _ := TestNamespaceCommands(GetDispatchRateCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/max_consumers_per_subscription_test.go b/pkg/ctl/namespace/max_consumers_per_subscription_test.go index 02b110bb..aceb005c 100644 --- a/pkg/ctl/namespace/max_consumers_per_subscription_test.go +++ b/pkg/ctl/namespace/max_consumers_per_subscription_test.go @@ -57,7 +57,7 @@ func TestSetMaxConsumersPerSubscriptionOnNonExistingTopic(t *testing.T) { args := []string{"set-max-consumers-per-subscription", "--size", "10", ns} _, execErr, _, _ := TestNamespaceCommands(SetMaxConsumersPerSubscriptionCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestSetMaxConsumersPerSubscriptionWithInvalidSize(t *testing.T) { @@ -72,5 +72,5 @@ func TestGetMaxConsumersPerSubscriptionOnNonExistingTopic(t *testing.T) { args := []string{"get-max-consumers-per-subscription", ns} _, execErr, _, _ := TestNamespaceCommands(GetMaxConsumersPerSubscriptionCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/max_consumers_per_topic_test.go b/pkg/ctl/namespace/max_consumers_per_topic_test.go index 5333217c..7890ae74 100644 --- a/pkg/ctl/namespace/max_consumers_per_topic_test.go +++ b/pkg/ctl/namespace/max_consumers_per_topic_test.go @@ -57,7 +57,7 @@ func TestSetMaxConsumersPerTopicOnNonExistingTopic(t *testing.T) { args := []string{"set-max-consumers-per-topic", "--size", "10", ns} _, execErr, _, _ := TestNamespaceCommands(SetMaxConsumersPerTopicCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestSetMaxConsumersPerTopicWithInvalidSize(t *testing.T) { @@ -72,5 +72,5 @@ func TestGetMaxConsumersPerTopicOnNonExistingTopic(t *testing.T) { args := []string{"get-max-consumers-per-topic", ns} _, execErr, _, _ := TestNamespaceCommands(GetMaxConsumersPerTopicCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/max_producers_per_topic_test.go b/pkg/ctl/namespace/max_producers_per_topic_test.go index 634a1c5a..fbb07a88 100644 --- a/pkg/ctl/namespace/max_producers_per_topic_test.go +++ b/pkg/ctl/namespace/max_producers_per_topic_test.go @@ -57,7 +57,7 @@ func TestSetMaxProducersPerTopicOnNonExistingTopic(t *testing.T) { args := []string{"set-max-producers-per-topic", "--size", "10", ns} _, execErr, _, _ := TestNamespaceCommands(SetMaxProducersPerTopicCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestSetMaxProducersPerTopicWithInvalidSize(t *testing.T) { @@ -72,5 +72,5 @@ func TestGetMaxProducersPerTopicOnNonExistingTopic(t *testing.T) { args := []string{"get-max-producers-per-topic", ns} _, execErr, _, _ := TestNamespaceCommands(GetMaxProducersPerTopicCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/offload_deletion_test.go b/pkg/ctl/namespace/offload_deletion_test.go index 6e3255b3..e79fa97f 100644 --- a/pkg/ctl/namespace/offload_deletion_test.go +++ b/pkg/ctl/namespace/offload_deletion_test.go @@ -72,7 +72,7 @@ func TestOffloadDeletionLagOnNonExistingNs(t *testing.T) { args := []string{"set-offload-deletion-lag", "--lag", "10m", ns} _, execErr, _, _ := TestNamespaceCommands(SetOffloadDeletionLagCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestGetOfloadThresholdOnNonExistingNs(t *testing.T) { @@ -80,7 +80,7 @@ func TestGetOfloadThresholdOnNonExistingNs(t *testing.T) { args := []string{"get-offload-deletion-lag", ns} _, execErr, _, _ := TestNamespaceCommands(GetOffloadDeletionLagCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestClearOffloadDeletionLagOnNonExistingNs(t *testing.T) { @@ -88,5 +88,5 @@ func TestClearOffloadDeletionLagOnNonExistingNs(t *testing.T) { args := []string{"clear-offload-deletion-lag", ns} _, execErr, _, _ := TestNamespaceCommands(ClearOffloadDeletionLagCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/offload_threshold_test.go b/pkg/ctl/namespace/offload_threshold_test.go index 26342399..9f49b6fe 100644 --- a/pkg/ctl/namespace/offload_threshold_test.go +++ b/pkg/ctl/namespace/offload_threshold_test.go @@ -57,7 +57,7 @@ func TestSetOffloadThresholdOnNonExistingNs(t *testing.T) { args := []string{"set-offload-threshold", "--size", "10m", ns} _, execErr, _, _ := TestNamespaceCommands(SetOffloadThresholdCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestGetOffloadThresholdOnNonExistingNs(t *testing.T) { @@ -65,5 +65,5 @@ func TestGetOffloadThresholdOnNonExistingNs(t *testing.T) { args := []string{"get-offload-threshold", ns} _, execErr, _, _ := TestNamespaceCommands(GetOffloadThresholdCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/policies_test.go b/pkg/ctl/namespace/policies_test.go index eabc2005..5ef9e24f 100644 --- a/pkg/ctl/namespace/policies_test.go +++ b/pkg/ctl/namespace/policies_test.go @@ -62,12 +62,12 @@ func TestPolicesNonExistTenant(t *testing.T) { args := []string{"policies", "non-existent-tenant/default"} _, execErr, _, _ := TestNamespaceCommands(getPolicies, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestPolicesNonExistNs(t *testing.T) { args := []string{"policies", "public/test-not-exist-ns"} _, execErr, _, _ := TestNamespaceCommands(getPolicies, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/publish_rate_test.go b/pkg/ctl/namespace/publish_rate_test.go index f26f8d78..f6b20653 100644 --- a/pkg/ctl/namespace/publish_rate_test.go +++ b/pkg/ctl/namespace/publish_rate_test.go @@ -102,5 +102,5 @@ func TestGetPublishRateOnNonExistingNs(t *testing.T) { args := []string{"get-publish-rate", ns} _, execErr, _, _ := TestNamespaceCommands(GetPublishRateCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/schema_autoupdate_strategy_test.go b/pkg/ctl/namespace/schema_autoupdate_strategy_test.go index 7ab00ff7..44ef2fcb 100644 --- a/pkg/ctl/namespace/schema_autoupdate_strategy_test.go +++ b/pkg/ctl/namespace/schema_autoupdate_strategy_test.go @@ -76,7 +76,7 @@ func TestSetSchemaAutoUpdateStrategyOnNonExistingNs(t *testing.T) { args := []string{"set-schema-autoupdate-strategy", ns} _, execErr, _, _ := TestNamespaceCommands(SetSchemaAutoUpdateStrategyCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestGetSchemaAutoUpdateStrategyOnNonExistingNs(t *testing.T) { @@ -84,5 +84,5 @@ func TestGetSchemaAutoUpdateStrategyOnNonExistingNs(t *testing.T) { args := []string{"get-schema-autoupdate-strategy", ns} _, execErr, _, _ := TestNamespaceCommands(GetSchemaAutoUpdateStrategyCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/schema_validation_enforce_test.go b/pkg/ctl/namespace/schema_validation_enforce_test.go index 8c661c29..f8f08076 100644 --- a/pkg/ctl/namespace/schema_validation_enforce_test.go +++ b/pkg/ctl/namespace/schema_validation_enforce_test.go @@ -51,7 +51,7 @@ func TestSetSchemaValidationEnforcedOnNonExistingNs(t *testing.T) { args := []string{"set-schema-validation-enforced", ns} _, execErr, _, _ := TestNamespaceCommands(SetSchemaValidationEnforcedCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestGetSchemaValidationEnforcedOnNonExistingNs(t *testing.T) { @@ -59,5 +59,5 @@ func TestGetSchemaValidationEnforcedOnNonExistingNs(t *testing.T) { args := []string{"get-schema-validation-enforced", ns} _, execErr, _, _ := TestNamespaceCommands(GetSchemaValidationEnforcedCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/set_subscription_auth_mode_test.go b/pkg/ctl/namespace/set_subscription_auth_mode_test.go index 8c35643f..20a2b5d1 100644 --- a/pkg/ctl/namespace/set_subscription_auth_mode_test.go +++ b/pkg/ctl/namespace/set_subscription_auth_mode_test.go @@ -76,8 +76,7 @@ func TestSetSubscriptionAuthModeOnNonExistingNs(t *testing.T) { args := []string{"set-subscription-auth-mode", "--mode", "Prefix", ns} _, execErr, _, _ := TestNamespaceCommands(SetSubscriptionAuthModeCmd, args) - assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestSetSubscriptionAuthModeWithInvalidMode(t *testing.T) { diff --git a/pkg/ctl/namespace/subscribe_rate_test.go b/pkg/ctl/namespace/subscribe_rate_test.go index 9798101e..37b1bd58 100644 --- a/pkg/ctl/namespace/subscribe_rate_test.go +++ b/pkg/ctl/namespace/subscribe_rate_test.go @@ -105,5 +105,5 @@ func TestGetSubscribeRateOnNonExistingNs(t *testing.T) { args := []string{"get-subscribe-rate", ns} _, execErr, _, _ := TestNamespaceCommands(GetSubscribeRateCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/subscription_dispatch_rate_test.go b/pkg/ctl/namespace/subscription_dispatch_rate_test.go index f8364df7..58a82d24 100644 --- a/pkg/ctl/namespace/subscription_dispatch_rate_test.go +++ b/pkg/ctl/namespace/subscription_dispatch_rate_test.go @@ -111,5 +111,5 @@ func TestGetSubscriptionDispatchRateOnNonExistingNs(t *testing.T) { args := []string{"get-subscription-dispatch-rate", ns} _, execErr, _, _ := TestNamespaceCommands(GetSubscriptionDispatchRateCmd, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/test_help.go b/pkg/ctl/namespace/test_help.go index b5725dc4..91efa910 100644 --- a/pkg/ctl/namespace/test_help.go +++ b/pkg/ctl/namespace/test_help.go @@ -19,13 +19,31 @@ package namespace import ( "bytes" + "testing" "github.com/streamnative/pulsarctl/pkg/cmdutils" "github.com/kris-nova/logger" "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" ) +func assertNamespaceNotExistError(t *testing.T, err error) { + t.Helper() + + if !assert.Error(t, err) { + return + } + + assert.Contains(t, + []string{ + "code: 404 reason: Namespace does not exist", + "code: 404 reason: Namespace not found", + }, + err.Error(), + ) +} + func TestNamespaceCommands(newVerb func(cmd *cmdutils.VerbCmd), args []string) (out *bytes.Buffer, execErr, nameErr, err error) { var execError error diff --git a/pkg/ctl/namespace/topics_test.go b/pkg/ctl/namespace/topics_test.go index b926ccd4..1c9fe39a 100644 --- a/pkg/ctl/namespace/topics_test.go +++ b/pkg/ctl/namespace/topics_test.go @@ -46,12 +46,12 @@ func TestListNonExistNamespace(t *testing.T) { args := []string{"topics", "public/non-exist-namespace"} _, execErr, _, _ := TestNamespaceCommands(getTopics, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } func TestListNonExistTenant(t *testing.T) { args := []string{"topics", "non-exist-tenant/default"} _, execErr, _, _ := TestNamespaceCommands(getTopics, args) assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) } diff --git a/pkg/ctl/namespace/unsubscribe_test.go b/pkg/ctl/namespace/unsubscribe_test.go index fca735cd..e79aa0d6 100644 --- a/pkg/ctl/namespace/unsubscribe_test.go +++ b/pkg/ctl/namespace/unsubscribe_test.go @@ -66,6 +66,5 @@ func TestUnsubscribeOnNonExistingNs(t *testing.T) { args := []string{"unsubscribe", "--bundle", "0xc0000000_0xffffffff", ns, "non-existing-sub"} _, execErr, _, _ := TestNamespaceCommands(UnsubscribeCmd, args) - assert.NotNil(t, execErr) - assert.Equal(t, "code: 404 reason: Namespace does not exist", execErr.Error()) + assertNamespaceNotExistError(t, execErr) }