github.com/hoveychen/kafka-go@v0.4.42/protocol/incrementalalterconfigs/incrementalalterconfigs_test.go (about) 1 package incrementalalterconfigs_test 2 3 import ( 4 "testing" 5 6 "github.com/hoveychen/kafka-go/protocol" 7 "github.com/hoveychen/kafka-go/protocol/incrementalalterconfigs" 8 ) 9 10 const ( 11 resourceTypeTopic int8 = 2 12 resourceTypeBroker int8 = 4 13 ) 14 15 func TestMetadataRequestBroker(t *testing.T) { 16 req := &incrementalalterconfigs.Request{ 17 Resources: []incrementalalterconfigs.RequestResource{ 18 { 19 ResourceType: resourceTypeBroker, 20 ResourceName: "1", 21 Configs: []incrementalalterconfigs.RequestConfig{ 22 { 23 Name: "test-name1", 24 Value: "test-value1", 25 }, 26 }, 27 }, 28 { 29 ResourceType: resourceTypeBroker, 30 ResourceName: "1", 31 Configs: []incrementalalterconfigs.RequestConfig{ 32 { 33 Name: "test-name2", 34 Value: "test-value2", 35 }, 36 }, 37 }, 38 { 39 ResourceType: resourceTypeTopic, 40 ResourceName: "test-topic1", 41 Configs: []incrementalalterconfigs.RequestConfig{ 42 { 43 Name: "test-name3", 44 Value: "test-value3", 45 }, 46 }, 47 }, 48 { 49 ResourceType: resourceTypeTopic, 50 ResourceName: "test-topic2", 51 Configs: []incrementalalterconfigs.RequestConfig{ 52 { 53 Name: "test-name4", 54 Value: "test-value4", 55 }, 56 }, 57 }, 58 }, 59 } 60 b, err := req.Broker(protocol.Cluster{ 61 Brokers: map[int32]protocol.Broker{ 62 0: { 63 ID: 0, 64 }, 65 1: { 66 ID: 1, 67 }, 68 }, 69 }) 70 if err != nil { 71 t.Fatal( 72 "Unexpected error getting request broker", 73 "expected", nil, 74 "got", err, 75 ) 76 } 77 if b.ID != 1 { 78 t.Error( 79 "Unexpected id returned for request broker", 80 "expected", 1, 81 "got", b.ID, 82 ) 83 } 84 85 req = &incrementalalterconfigs.Request{ 86 Resources: []incrementalalterconfigs.RequestResource{ 87 { 88 ResourceType: resourceTypeBroker, 89 ResourceName: "1", 90 Configs: []incrementalalterconfigs.RequestConfig{ 91 { 92 Name: "test-name1", 93 Value: "test-value1", 94 }, 95 }, 96 }, 97 { 98 ResourceType: resourceTypeBroker, 99 ResourceName: "2", 100 Configs: []incrementalalterconfigs.RequestConfig{ 101 { 102 Name: "test-name2", 103 Value: "test-value2", 104 }, 105 }, 106 }, 107 }, 108 } 109 110 _, err = req.Broker(protocol.Cluster{ 111 Brokers: map[int32]protocol.Broker{ 112 0: { 113 ID: 0, 114 }, 115 1: { 116 ID: 1, 117 }, 118 2: { 119 ID: 1, 120 }, 121 }, 122 }) 123 if err == nil { 124 t.Fatal( 125 "Unexpected error getting request broker", 126 "expected", "non-nil", 127 "got", err, 128 ) 129 } 130 }