@@ -447,6 +447,7 @@ func TestNamespaces_SetSchemaCompatibilityStrategy(t *testing.T) {
447447}
448448
449449func TestNamespaces_GetSchemaCompatibilityStrategy (t * testing.T ) {
450+
450451 config := & config.Config {}
451452 admin , err := New (config )
452453 require .NoError (t , err )
@@ -496,6 +497,56 @@ func TestNamespaces_GetSchemaCompatibilityStrategy(t *testing.T) {
496497 assert .Equal (t , utils .SchemaCompatibilityStrategyUndefined , defaultStrategy )
497498}
498499
500+ func TestNamespaces_SetMaxTopicsPerNamespace (t * testing.T ) {
501+ config := & config.Config {}
502+ admin , err := New (config )
503+ require .NoError (t , err )
504+ require .NotNil (t , admin )
505+
506+ tests := []struct {
507+ name string
508+ namespace string
509+ maxTopics int
510+ errReason string
511+ }{
512+ {
513+ name : "Set valid max topics per namespace" ,
514+ namespace : "public/default" ,
515+ maxTopics : 100 ,
516+ errReason : "" ,
517+ },
518+ {
519+ name : "Set invalid max topics per namespace" ,
520+ namespace : "public/default" ,
521+ maxTopics : - 1 ,
522+ errReason : "maxTopicsPerNamespace must be 0 or more" ,
523+ },
524+ {
525+ name : "Set valid max topics per namespace: 0" ,
526+ namespace : "public/default" ,
527+ maxTopics : 0 ,
528+ errReason : "" ,
529+ },
530+ }
531+ for _ , tt := range tests {
532+ t .Run (tt .name , func (t * testing.T ) {
533+ namespace , _ := utils .GetNamespaceName (tt .namespace )
534+ err := admin .Namespaces ().SetMaxTopicsPerNamespace (* namespace , tt .maxTopics )
535+ if tt .errReason == "" {
536+ assert .Equal (t , nil , err )
537+
538+ err = admin .Namespaces ().RemoveMaxTopicsPerNamespace (* namespace )
539+ assert .Equal (t , nil , err )
540+ }
541+ if err != nil {
542+ restError := err .(rest.Error )
543+ assert .Equal (t , tt .errReason , restError .Reason )
544+ }
545+ })
546+ }
547+
548+ }
549+
499550func TestNamespaces_Properties (t * testing.T ) {
500551 config := & config.Config {}
501552 admin , err := New (config )
@@ -523,3 +574,30 @@ func TestNamespaces_Properties(t *testing.T) {
523574 assert .Equal (t , err , nil )
524575 assert .Equal (t , actualPropertiesAfterRemoveCall , map [string ]string {})
525576}
577+
578+ func TestNamespaces_GetMaxTopicsPerNamespace (t * testing.T ) {
579+
580+ config := & config.Config {}
581+ admin , err := New (config )
582+ require .NoError (t , err )
583+ require .NotNil (t , admin )
584+
585+ namespace , _ := utils .GetNamespaceName ("public/default" )
586+
587+ // set the max topics per namespace and get it
588+ err = admin .Namespaces ().SetMaxTopicsPerNamespace (* namespace , 100 )
589+ assert .Equal (t , nil , err )
590+ maxTopics , err := admin .Namespaces ().GetMaxTopicsPerNamespace (* namespace )
591+ assert .Equal (t , nil , err )
592+ expected := 100
593+ assert .Equal (t , expected , maxTopics )
594+
595+ // remove the max topics per namespace and get it
596+ err = admin .Namespaces ().RemoveMaxTopicsPerNamespace (* namespace )
597+ assert .Equal (t , nil , err )
598+
599+ maxTopics , err = admin .Namespaces ().GetMaxTopicsPerNamespace (* namespace )
600+ assert .Equal (t , nil , err )
601+ expected = 0
602+ assert .Equal (t , expected , maxTopics )
603+ }
0 commit comments