github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/deleteacls_test.go (about)

     1  package kafka
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	ktesting "github.com/segmentio/kafka-go/testing"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestClientDeleteACLs(t *testing.T) {
    12  	if !ktesting.KafkaIsAtLeast("2.0.1") {
    13  		return
    14  	}
    15  
    16  	client, shutdown := newLocalClient()
    17  	defer shutdown()
    18  
    19  	topic := makeTopic()
    20  	group := makeGroupID()
    21  
    22  	createRes, err := client.CreateACLs(context.Background(), &CreateACLsRequest{
    23  		ACLs: []ACLEntry{
    24  			{
    25  				Principal:           "User:alice",
    26  				PermissionType:      ACLPermissionTypeAllow,
    27  				Operation:           ACLOperationTypeRead,
    28  				ResourceType:        ResourceTypeTopic,
    29  				ResourcePatternType: PatternTypeLiteral,
    30  				ResourceName:        topic,
    31  				Host:                "*",
    32  			},
    33  			{
    34  				Principal:           "User:bob",
    35  				PermissionType:      ACLPermissionTypeAllow,
    36  				Operation:           ACLOperationTypeRead,
    37  				ResourceType:        ResourceTypeGroup,
    38  				ResourcePatternType: PatternTypeLiteral,
    39  				ResourceName:        group,
    40  				Host:                "*",
    41  			},
    42  		},
    43  	})
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  
    48  	for _, err := range createRes.Errors {
    49  		if err != nil {
    50  			t.Error(err)
    51  		}
    52  	}
    53  
    54  	deleteResp, err := client.DeleteACLs(context.Background(), &DeleteACLsRequest{
    55  		Filters: []DeleteACLsFilter{
    56  			{
    57  				ResourceTypeFilter:        ResourceTypeTopic,
    58  				ResourceNameFilter:        topic,
    59  				ResourcePatternTypeFilter: PatternTypeLiteral,
    60  				Operation:                 ACLOperationTypeRead,
    61  				PermissionType:            ACLPermissionTypeAllow,
    62  			},
    63  		},
    64  	})
    65  	if err != nil {
    66  		t.Fatal(err)
    67  	}
    68  
    69  	expectedDeleteResp := DeleteACLsResponse{
    70  		Throttle: 0,
    71  		Results: []DeleteACLsResult{
    72  			{
    73  				Error: makeError(0, ""),
    74  				MatchingACLs: []DeleteACLsMatchingACLs{
    75  					{
    76  						Error:               makeError(0, ""),
    77  						ResourceType:        ResourceTypeTopic,
    78  						ResourceName:        topic,
    79  						ResourcePatternType: PatternTypeLiteral,
    80  						Principal:           "User:alice",
    81  						Host:                "*",
    82  						Operation:           ACLOperationTypeRead,
    83  						PermissionType:      ACLPermissionTypeAllow,
    84  					},
    85  				},
    86  			},
    87  		},
    88  	}
    89  
    90  	assert.Equal(t, expectedDeleteResp, *deleteResp)
    91  
    92  	describeResp, err := client.DescribeACLs(context.Background(), &DescribeACLsRequest{
    93  		Filter: ACLFilter{
    94  			ResourceTypeFilter:        ResourceTypeTopic,
    95  			ResourceNameFilter:        topic,
    96  			ResourcePatternTypeFilter: PatternTypeLiteral,
    97  			Operation:                 ACLOperationTypeRead,
    98  			PermissionType:            ACLPermissionTypeAllow,
    99  		},
   100  	})
   101  	if err != nil {
   102  		t.Fatal(err)
   103  	}
   104  
   105  	expectedDescribeResp := DescribeACLsResponse{
   106  		Throttle:  0,
   107  		Error:     makeError(0, ""),
   108  		Resources: []ACLResource{},
   109  	}
   110  
   111  	assert.Equal(t, expectedDescribeResp, *describeResp)
   112  }