-
Notifications
You must be signed in to change notification settings - Fork 0
/
drift_enums_test.go
76 lines (71 loc) · 1.84 KB
/
drift_enums_test.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
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
package pgutil
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUnifyLabels(t *testing.T) {
for _, testCase := range []struct {
name string
expectedLabels []string
existingLabels []string
valid bool
reconstruction []missingLabel
}{
{
name: "mismatched",
expectedLabels: []string{"foo", "bar", "baz"},
existingLabels: []string{"foo", "baz", "bonk"},
valid: false,
},
{
name: "inversions",
expectedLabels: []string{"foo", "bar", "baz"},
existingLabels: []string{"baz", "bar"},
valid: false,
},
{
name: "missing at end",
expectedLabels: []string{"foo", "bar", "baz", "bonk"},
existingLabels: []string{"foo", "bar"},
valid: true,
reconstruction: []missingLabel{
{Label: "baz", Prev: ptr("bar")},
{Label: "bonk", Prev: ptr("baz")},
},
},
{
name: "missing in middle",
expectedLabels: []string{"foo", "bar", "baz", "bonk"},
existingLabels: []string{"foo", "bonk"},
valid: true,
reconstruction: []missingLabel{
{Label: "bar", Prev: ptr("foo")},
{Label: "baz", Prev: ptr("bar")},
},
},
{
name: "missing at beginning",
expectedLabels: []string{"foo", "bar", "baz", "bonk"},
existingLabels: []string{"baz", "bonk"},
valid: true,
reconstruction: []missingLabel{
{Label: "foo", Next: ptr("baz")},
{Label: "bar", Prev: ptr("foo")},
},
},
} {
t.Run(testCase.name, func(t *testing.T) {
reconstruction, valid := unifyLabels(testCase.expectedLabels, testCase.existingLabels)
if testCase.valid {
require.True(t, valid)
assert.Equal(t, testCase.reconstruction, reconstruction)
} else {
require.False(t, valid)
}
})
}
}
func ptr[S any](v S) *S {
return &v
}