-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
utils.go
36 lines (31 loc) · 824 Bytes
/
utils.go
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
package kafka
import (
"fmt"
)
// MapEq compares two maps, and checks that the keys and values are the same
func MapEq(result, expected map[string]*string) error {
if len(result) != len(expected) {
return fmt.Errorf("%v != %v", result, expected)
}
for expectedK, expectedV := range expected {
if resultV, ok := result[expectedK]; ok {
if resultV == nil && expectedV == nil {
continue
}
if *resultV != *expectedV {
return fmt.Errorf("result[%s]: %s != expected[%s]: %s", expectedK, *resultV, expectedK, *expectedV)
}
} else {
return fmt.Errorf("result[%s] should exist", expectedK)
}
}
return nil
}
// TODO: can I just get rid of this?
func strPtrMapToStrMap(c map[string]*string) map[string]string {
foo := map[string]string{}
for k, v := range c {
foo[k] = *v
}
return foo
}