@@ -65,37 +65,63 @@ func TestCreateTopic(t *testing.T) {
65
65
t .Error ("Couldn't find topic: " + topic )
66
66
}
67
67
68
- func TestTopics_CreateWithProperties (t * testing.T ) {
68
+ func TestTopics_Properties (t * testing.T ) {
69
+ t .Run ("NonPartitioned" , func (t * testing.T ) {
70
+ internalTestTopicsProperties (t , 0 )
71
+ })
72
+ t .Run ("Partitioned" , func (t * testing.T ) {
73
+ internalTestTopicsProperties (t , 4 )
74
+ })
75
+ }
76
+
77
+ func verifyTopicProperties (t * testing.T , admin Client , topic * utils.TopicName ,
78
+ expected map [string ]string ) {
79
+ properties , err := admin .Topics ().GetProperties (* topic )
80
+ assert .NoError (t , err )
81
+ assert .Equal (t , expected , properties )
82
+ }
83
+
84
+ func internalTestTopicsProperties (t * testing.T , partitions int ) {
69
85
topic := newTopicName ()
70
86
cfg := & config.Config {}
71
87
admin , err := New (cfg )
72
88
assert .NoError (t , err )
73
89
assert .NotNil (t , admin )
74
90
75
- // Create non-partition topic
76
91
topicName , err := utils .GetTopicName (topic )
77
92
assert .NoError (t , err )
78
- err = admin .Topics ().CreateWithProperties (* topicName , 0 , map [string ]string {
93
+ err = admin .Topics ().CreateWithProperties (* topicName , partitions , map [string ]string {
79
94
"key1" : "value1" ,
80
95
})
81
96
assert .NoError (t , err )
97
+ verifyTopicProperties (t , admin , topicName , map [string ]string {"key1" : "value1" })
82
98
83
99
properties , err := admin .Topics ().GetProperties (* topicName )
84
100
assert .NoError (t , err )
85
101
assert .Equal (t , properties ["key1" ], "value1" )
86
102
87
- // Create partition topic
88
- topic = newTopicName ()
89
- topicName , err = utils .GetTopicName (topic )
103
+ newProperties := map [string ]string {
104
+ "key1" : "value1-updated" ,
105
+ "key2" : "value2" ,
106
+ }
107
+ err = admin .Topics ().UpdateProperties (* topicName , newProperties )
108
+ assert .NoError (t , err )
109
+ verifyTopicProperties (t , admin , topicName , newProperties )
110
+
111
+ err = admin .Topics ().UpdateProperties (* topicName , map [string ]string {"key3" : "value3" })
90
112
assert .NoError (t , err )
91
- err = admin .Topics ().CreateWithProperties (* topicName , 4 , map [string ]string {
113
+ verifyTopicProperties (t , admin , topicName , map [string ]string {
114
+ "key1" : "value1-updated" ,
92
115
"key2" : "value2" ,
116
+ "key3" : "value3" ,
93
117
})
94
- assert .NoError (t , err )
95
118
96
- properties , err = admin .Topics ().GetProperties (* topicName )
119
+ err = admin .Topics ().RemoveProperty (* topicName , "key1" )
97
120
assert .NoError (t , err )
98
- assert .Equal (t , properties ["key2" ], "value2" )
121
+ verifyTopicProperties (t , admin , topicName , map [string ]string {
122
+ "key2" : "value2" ,
123
+ "key3" : "value3" ,
124
+ })
99
125
}
100
126
101
127
func TestPartitionState (t * testing.T ) {
0 commit comments