mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
refactor: extract types and pkgs to new files
This commit is contained in:
parent
4a92a03f31
commit
e109a7a6ce
15 changed files with 71 additions and 57 deletions
66
internal/util/util_test.go
Normal file
66
internal/util/util_test.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestSliceEqual_True(t *testing.T) {
|
||||
s1 := []string{"a", "b", "c"}
|
||||
s2 := []string{"a", "b", "c"}
|
||||
|
||||
result := SliceEqual(s1, s2)
|
||||
|
||||
assert.True(t, result)
|
||||
}
|
||||
|
||||
func TestSliceEqual_DifferentLengths(t *testing.T) {
|
||||
s1 := []string{"a", "b", "c"}
|
||||
s2 := []string{"a", "b", "c", "d"}
|
||||
|
||||
result := SliceEqual(s1, s2)
|
||||
|
||||
assert.False(t, result)
|
||||
}
|
||||
|
||||
func TestSliceEqual_DifferentContents(t *testing.T) {
|
||||
s1 := []string{"a", "b", "c"}
|
||||
s2 := []string{"a", "b", "d"}
|
||||
|
||||
result := SliceEqual(s1, s2)
|
||||
|
||||
assert.False(t, result)
|
||||
}
|
||||
|
||||
func TestSliceSubtract(t *testing.T) {
|
||||
a1 := []string{"a", "b", "c"}
|
||||
a2 := []string{"a", "c"}
|
||||
|
||||
result := SliceSubtract(a1, a2)
|
||||
assert.Equal(t, []string{"b"}, result)
|
||||
assert.Equal(t, []string{"a", "b", "c"}, a1)
|
||||
assert.Equal(t, []string{"a", "c"}, a2)
|
||||
}
|
||||
|
||||
func TestStringMapSubtract(t *testing.T) {
|
||||
m1 := map[string]string{"a": "a", "b": "b", "c": "sea"}
|
||||
m2 := map[string]string{"a": "a", "c": "c"}
|
||||
|
||||
result := StringMapSubtract(m1, m2)
|
||||
assert.Equal(t, map[string]string{"b": "b", "c": "sea"}, result)
|
||||
assert.Equal(t, map[string]string{"a": "a", "b": "b", "c": "sea"}, m1)
|
||||
assert.Equal(t, map[string]string{"a": "a", "c": "c"}, m2)
|
||||
}
|
||||
|
||||
func TestStructMapSubtract(t *testing.T) {
|
||||
x := struct{}{}
|
||||
m1 := map[string]struct{}{"a": x, "b": x, "c": x}
|
||||
m2 := map[string]struct{}{"a": x, "c": x}
|
||||
|
||||
result := StructMapSubtract(m1, m2)
|
||||
assert.Equal(t, map[string]struct{}{"b": x}, result)
|
||||
assert.Equal(t, map[string]struct{}{"a": x, "b": x, "c": x}, m1)
|
||||
assert.Equal(t, map[string]struct{}{"a": x, "c": x}, m2)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue