| 9 | ) |
| 10 | |
| 11 | func TestSubscription(t *testing.T) { |
| 12 | subscription := consumer.Subscription{ |
| 13 | Topics: []string{"topic-1", "topic-2"}, |
| 14 | UserData: []byte("user-data"), |
| 15 | OwnedPartitions: []consumer.TopicPartition{ |
| 16 | { |
| 17 | Topic: "topic-1", |
| 18 | Partitions: []int32{1, 2, 3}, |
| 19 | }, |
| 20 | }, |
| 21 | } |
| 22 | |
| 23 | for _, version := range []int16{1, 0} { |
| 24 | if version == 0 { |
| 25 | subscription.OwnedPartitions = nil |
| 26 | } |
| 27 | data, err := protocol.Marshal(version, subscription) |
| 28 | if err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | var gotSubscription consumer.Subscription |
| 32 | err = protocol.Unmarshal(data, version, &gotSubscription) |
| 33 | if err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | if !reflect.DeepEqual(subscription, gotSubscription) { |
| 37 | t.Fatalf("unexpected result after marshal/unmarshal \nexpected\n %#v\ngot\n %#v", subscription, gotSubscription) |
| 38 | } |
| 39 | } |
| 40 | } |