Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/clear_backlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/compaction_threshold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ 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) {
ns := "public/non-existing-namespace"
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)
}
2 changes: 1 addition & 1 deletion pkg/ctl/namespace/dispatch_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/max_consumers_per_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/max_consumers_per_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/max_producers_per_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions pkg/ctl/namespace/offload_deletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ 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) {
ns := "public/non-existing-namespace"
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) {
ns := "public/non-existing-namespace"
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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/offload_threshold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ 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) {
ns := "public/non-existing-namespace"
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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/ctl/namespace/publish_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/schema_autoupdate_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ 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) {
ns := "public/non-existing-namespace"
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)
}
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/schema_validation_enforce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ 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) {
ns := "public/non-existing-namespace"
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)
}
3 changes: 1 addition & 2 deletions pkg/ctl/namespace/set_subscription_auth_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/namespace/subscribe_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/ctl/namespace/subscription_dispatch_rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 18 additions & 0 deletions pkg/ctl/namespace/test_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/ctl/namespace/topics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions pkg/ctl/namespace/unsubscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading