File: describe_client_quotas_request_test.go

package info (click to toggle)
golang-github-ibm-sarama 1.45.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,964 kB
  • sloc: makefile: 35; sh: 19
file content (86 lines) | stat: -rw-r--r-- 2,363 bytes parent folder | download
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
//go:build !functional

package sarama

import "testing"

var (
	describeClientQuotasRequestAll = []byte{
		0, 0, 0, 0, // components len
		0, // strict
	}

	describeClientQuotasRequestDefaultUser = []byte{
		0, 0, 0, 1, // components len
		0, 4, 'u', 's', 'e', 'r', // entity type
		1,    // match type (default)
		0, 0, // match *string
		0, // strict
	}

	describeClientQuotasRequestOnlySpecificUser = []byte{
		0, 0, 0, 1, // components len
		0, 4, 'u', 's', 'e', 'r', // entity type
		0,                                  // match type (exact)
		0, 6, 's', 'a', 'r', 'a', 'm', 'a', // match *string
		1, // strict
	}

	describeClientQuotasRequestMultiComponents = []byte{
		0, 0, 0, 2, // components len
		0, 4, 'u', 's', 'e', 'r', // entity type
		2,        // match type (any)
		255, 255, // match *string
		0, 9, 'c', 'l', 'i', 'e', 'n', 't', '-', 'i', 'd', // entity type
		1,    // match type (default)
		0, 0, // match *string
		0, // strict
	}
)

func TestDescribeClientQuotasRequest(t *testing.T) {
	// Match All
	req := &DescribeClientQuotasRequest{
		Components: []QuotaFilterComponent{},
		Strict:     false,
	}
	testRequest(t, "Match All", req, describeClientQuotasRequestAll)

	// Match Default User
	defaultUser := QuotaFilterComponent{
		EntityType: QuotaEntityUser,
		MatchType:  QuotaMatchDefault,
	}
	req = &DescribeClientQuotasRequest{
		Components: []QuotaFilterComponent{defaultUser},
		Strict:     false,
	}
	testRequest(t, "Match Default User", req, describeClientQuotasRequestDefaultUser)

	// Match Only Specific User
	specificUser := QuotaFilterComponent{
		EntityType: QuotaEntityUser,
		MatchType:  QuotaMatchExact,
		Match:      "sarama",
	}
	req = &DescribeClientQuotasRequest{
		Components: []QuotaFilterComponent{specificUser},
		Strict:     true,
	}
	testRequest(t, "Match Only Specific User", req, describeClientQuotasRequestOnlySpecificUser)

	// Match default client-id of any user
	anyUser := QuotaFilterComponent{
		EntityType: QuotaEntityUser,
		MatchType:  QuotaMatchAny,
	}
	defaultClientId := QuotaFilterComponent{
		EntityType: QuotaEntityClientID,
		MatchType:  QuotaMatchDefault,
	}
	req = &DescribeClientQuotasRequest{
		Components: []QuotaFilterComponent{anyUser, defaultClientId},
		Strict:     false,
	}
	testRequest(t, "Match default client-id of any user", req, describeClientQuotasRequestMultiComponents)
}