File: resource_test.go

package info (click to toggle)
golang-github-segmentio-kafka-go 0.4.49%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,292 kB
  • sloc: sh: 17; makefile: 10
file content (58 lines) | stat: -rw-r--r-- 1,551 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
package kafka

import "testing"

func TestResourceTypeMarshal(t *testing.T) {
	for i := ResourceTypeUnknown; i <= ResourceTypeDelegationToken; i++ {
		text, err := i.MarshalText()
		if err != nil {
			t.Errorf("couldn't marshal %d to text: %s", i, err)
		}
		var got ResourceType
		err = got.UnmarshalText(text)
		if err != nil {
			t.Errorf("couldn't unmarshal %s to ResourceType: %s", text, err)
		}
		if got != i {
			t.Errorf("got %d, want %d", got, i)
		}
	}
}

// Verify that the text version of ResourceTypeBroker is "Cluster".
// This is added since ResourceTypeBroker and ResourceTypeCluster
// have the same value.
func TestResourceTypeBroker(t *testing.T) {
	text, err := ResourceTypeBroker.MarshalText()
	if err != nil {
		t.Errorf("couldn't marshal %d to text: %s", ResourceTypeBroker, err)
	}
	if string(text) != "Cluster" {
		t.Errorf("got %s, want %s", string(text), "Cluster")
	}
	var got ResourceType
	err = got.UnmarshalText(text)
	if err != nil {
		t.Errorf("couldn't unmarshal %s to ResourceType: %s", text, err)
	}
	if got != ResourceTypeBroker {
		t.Errorf("got %d, want %d", got, ResourceTypeBroker)
	}
}

func TestPatternTypeMarshal(t *testing.T) {
	for i := PatternTypeUnknown; i <= PatternTypePrefixed; i++ {
		text, err := i.MarshalText()
		if err != nil {
			t.Errorf("couldn't marshal %d to text: %s", i, err)
		}
		var got PatternType
		err = got.UnmarshalText(text)
		if err != nil {
			t.Errorf("couldn't unmarshal %s to PatternType: %s", text, err)
		}
		if got != i {
			t.Errorf("got %d, want %d", got, i)
		}
	}
}