Repository navigation
Expand file tree
/
Copy pathalter_configs_response_test.go
More file actions
93 lines (79 loc) · 2.02 KB
/
Copy pathalter_configs_response_test.go
File metadata and controls
93 lines (79 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//go:build !functional
package sarama
import (
"errors"
"testing"
)
var (
alterResponseEmpty = []byte{
0, 0, 0, 0, // throttle
0, 0, 0, 0, // no configs
}
alterResponsePopulated = []byte{
0, 0, 0, 0, // throttle
0, 0, 0, 1, // response
0, 0, // errorcode
0, 0, // string
2, // topic
0, 3, 'f', 'o', 'o',
}
alterResponsePopulatedV2 = []byte{
0, 0, 0, 0, // ThrottleTimeMs
2, // Responses
0, 0, // ErrorCode
1, // ErrorMessage
2, // ResourceType
4, 'f', 'o', 'o', // ResourceName
0, // tagged fields (resource)
0, // tagged fields
}
)
func TestAlterConfigsResponse(t *testing.T) {
var response *AlterConfigsResponse
response = &AlterConfigsResponse{
Resources: []*AlterConfigsResourceResponse{},
}
testVersionDecodable(t, "empty", response, alterResponseEmpty, 0)
if len(response.Resources) != 0 {
t.Error("Expected no groups")
}
response = &AlterConfigsResponse{
Resources: []*AlterConfigsResourceResponse{
{
ErrorCode: 0,
ErrorMsg: "",
Type: TopicResource,
Name: "foo",
},
},
}
testResponse(t, "response with error", response, alterResponsePopulated)
response.Version = 2
testResponse(t, "response with error v2", response, alterResponsePopulatedV2)
}
func TestAlterConfigError(t *testing.T) {
// Assert that AlterConfigError satisfies error interface
var err error = &AlterConfigError{
Err: ErrInvalidConfig,
}
if !errors.Is(err, ErrInvalidConfig) {
t.Errorf("expected errors.Is to match ErrInvalidConfig")
}
got := err.Error()
want := ErrInvalidConfig.Error()
if got != want {
t.Errorf("AlterConfigError.Error() = %v; want %v", got, want)
}
err = &AlterConfigError{
Err: ErrInvalidConfig,
ErrMsg: "invalid config value",
}
got = err.Error()
want = ErrInvalidConfig.Error() + " - invalid config value"
if got != want {
t.Errorf("AlterConfigError.Error() = %v; want %v", got, want)
}
if !errors.Is(err, ErrInvalidConfig) {
t.Errorf("expected errors.Is to match ErrInvalidConfig with ErrMsg set")
}
}