Skip to content

Commit

Permalink
add basic mocks for consumer group responses
Browse files Browse the repository at this point in the history
  • Loading branch information
carldunham committed Feb 25, 2020
1 parent 4a4c720 commit f549c07
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions mockresponses.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,3 +992,133 @@ func (m *MockDeleteGroupsResponse) For(reqBody versionedDecoder) encoder {
}
return resp
}

type MockJoinGroupResponse struct {
t TestReporter

ThrottleTime int32
Err KError
GenerationId int32
GroupProtocol string
LeaderId string
Members map[string][]byte
}

func NewMockJoinGroupResponse(t TestReporter) *MockJoinGroupResponse {
return &MockJoinGroupResponse{
t: t,

Members: make(map[string][]byte),
}
}

func (m *MockJoinGroupResponse) For(reqBody versionedDecoder) encoder {
req := reqBody.(*JoinGroupRequest)
resp := &JoinGroupResponse{
Version: req.Version,
ThrottleTime: m.ThrottleTime,
Err: m.Err,
GenerationId: m.GenerationId,
GroupProtocol: m.GroupProtocol,
LeaderId: m.LeaderId,
MemberId: req.MemberId,
Members: m.Members,
}
return resp
}

func (m *MockJoinGroupResponse) SetThrottleTime(t int32) *MockJoinGroupResponse {
m.ThrottleTime = t
return m
}

func (m *MockJoinGroupResponse) SetError(kerr KError) *MockJoinGroupResponse {
m.Err = kerr
return m
}

func (m *MockJoinGroupResponse) SetGenerationId(id int32) *MockJoinGroupResponse {
m.GenerationId = id
return m
}

func (m *MockJoinGroupResponse) SetGroupProtocol(proto string) *MockJoinGroupResponse {
m.GroupProtocol = proto
return m
}

func (m *MockJoinGroupResponse) SetLeaderId(id string) *MockJoinGroupResponse {
m.LeaderId = id
return m
}

func (m *MockJoinGroupResponse) SetMember(id string, meta []byte) *MockJoinGroupResponse {
m.Members[id] = meta
return m
}

type MockLeaveGroupResponse struct {
t TestReporter

Err KError
}

func NewMockLeaveGroupResponse(t TestReporter) *MockLeaveGroupResponse {
return &MockLeaveGroupResponse{t: t}
}

func (m *MockLeaveGroupResponse) For(reqBody versionedDecoder) encoder {
resp := &LeaveGroupResponse{}
return resp
}

func (m *MockLeaveGroupResponse) SetError(kerr KError) *MockLeaveGroupResponse {
m.Err = kerr
return m
}

type MockSyncGroupResponse struct {
t TestReporter

Err KError
MemberAssignment []byte
}

func NewMockSyncGroupResponse(t TestReporter) *MockSyncGroupResponse {
return &MockSyncGroupResponse{t: t}
}

func (m *MockSyncGroupResponse) For(reqBody versionedDecoder) encoder {
resp := &SyncGroupResponse{}
return resp
}

func (m *MockSyncGroupResponse) SetError(kerr KError) *MockSyncGroupResponse {
m.Err = kerr
return m
}

func (m *MockSyncGroupResponse) SetMemberAssignment(raw []byte) *MockSyncGroupResponse {
m.MemberAssignment = raw
return m
}

type MockHeartbeatResponse struct {
t TestReporter

Err KError
}

func NewMockHeartbeatResponse(t TestReporter) *MockHeartbeatResponse {
return &MockHeartbeatResponse{t: t}
}

func (m *MockHeartbeatResponse) For(reqBody versionedDecoder) encoder {
resp := &HeartbeatResponse{}
return resp
}

func (m *MockHeartbeatResponse) SetError(kerr KError) *MockHeartbeatResponse {
m.Err = kerr
return m
}

0 comments on commit f549c07

Please sign in to comment.