MCPcopy
hub / github.com/IBM/sarama / TestClusterAdminDescribeUserScramCredentials

Function TestClusterAdminDescribeUserScramCredentials

admin_test.go:1604–1642  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1602}
1603
1604func TestClusterAdminDescribeUserScramCredentials(t *testing.T) {
1605 users := []string{"my_user"}
1606 describeOK := func(req *request) encoderWithHeader {
1607 return &DescribeUserScramCredentialsResponse{
1608 Version: req.body.version(),
1609 Results: []*DescribeUserScramCredentialsResult{{User: "my_user"}},
1610 }
1611 }
1612 notController := func(req *request) encoderWithHeader {
1613 return &DescribeUserScramCredentialsResponse{Version: req.body.version(), ErrorCode: ErrNotController}
1614 }
1615
1616 t.Run("describes credentials", func(t *testing.T) {
1617 admin := singleBrokerAdmin(t, V2_7_0_0, map[string]requestHandlerFunc{
1618 "DescribeUserScramCredentialsRequest": describeOK,
1619 })
1620
1621 results, err := admin.DescribeUserScramCredentials(users)
1622 require.NoError(t, err)
1623 assert.NotEmpty(t, results)
1624 })
1625
1626 t.Run("retries on stale controller", func(t *testing.T) {
1627 admin, retriedOnNewController := staleControllerAdmin(t, V2_7_0_0, "DescribeUserScramCredentialsRequest", notController, describeOK)
1628
1629 results, err := admin.DescribeUserScramCredentials(users)
1630 require.NoError(t, err)
1631 assert.NotEmpty(t, results)
1632 assert.True(t, retriedOnNewController(), "expected broker 2 to receive the retried request")
1633 })
1634
1635 t.Run("returns error when retries exhausted", func(t *testing.T) {
1636 admin, _ := staleControllerAdmin(t, V2_7_0_0, "DescribeUserScramCredentialsRequest", notController, notController)
1637
1638 _, err := admin.DescribeUserScramCredentials(users)
1639 require.Error(t, err)
1640 assert.ErrorIs(t, err, ErrNotController)
1641 })
1642}
1643
1644func TestElectLeaders(t *testing.T) {
1645 broker := NewMockBroker(t, 1)

Callers

nothing calls this directly

Calls 6

singleBrokerAdminFunction · 0.85
staleControllerAdminFunction · 0.85
RunMethod · 0.80
versionMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected