Skip to content

Commit

Permalink
Handle when there are 0 ConfigNames
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey committed Jan 14, 2018
1 parent 0bbd549 commit be19b6a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
24 changes: 22 additions & 2 deletions describe_configs_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (r *DescribeConfigsRequest) encode(pe packetEncoder) error {
if err := pe.putString(c.Name); err != nil {
return err
}

if len(c.ConfigNames) == 0 {
pe.putInt32(-1)
continue
}
if err := pe.putStringArray(c.ConfigNames); err != nil {
return err
}
Expand Down Expand Up @@ -48,11 +53,26 @@ func (r *DescribeConfigsRequest) decode(pd packetDecoder, version int16) (err er
return err
}
r.Resources[i].Name = name
s, err := pd.getStringArray()

confLength, err := pd.getArrayLength()

if err != nil {
return err
}
r.Resources[i].ConfigNames = s

if confLength == -1 {
continue
}

cfnames := make([]string, confLength)
for i := 0; i < confLength; i++ {
s, err := pd.getString()
if err != nil {
return err
}
cfnames[i] = s
}
r.Resources[i].ConfigNames = cfnames
}

return nil
Expand Down
21 changes: 20 additions & 1 deletion describe_configs_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ var (
0, 10, // 10 chars
's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
}

singleDescribeConfigsRequestAllConfigs = []byte{
0, 0, 0, 1, // 1 config
2, // a topic
0, 3, 'f', 'o', 'o', // topic name: foo
255, 255, 255, 255, // no configs
}
)

func TestDescribeConfigsRequest(t *testing.T) {
Expand All @@ -41,12 +48,13 @@ func TestDescribeConfigsRequest(t *testing.T) {
}
testRequest(t, "no requests", request, emptyDescribeConfigsRequest)

configs := []string{"segment.ms"}
request = &DescribeConfigsRequest{
Resources: []*Resource{
&Resource{
Type: TopicResource,
Name: "foo",
ConfigNames: []string{"segment.ms"},
ConfigNames: configs,
},
},
}
Expand All @@ -68,4 +76,15 @@ func TestDescribeConfigsRequest(t *testing.T) {
},
}
testRequest(t, "two configs", request, doubleDescribeConfigsRequest)

request = &DescribeConfigsRequest{
Resources: []*Resource{
&Resource{
Type: TopicResource,
Name: "foo",
},
},
}

testRequest(t, "one topic, all configs", request, singleDescribeConfigsRequestAllConfigs)
}

0 comments on commit be19b6a

Please sign in to comment.