feat(agent): diff inventories and debounce docker events
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package inventory
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/shcizo/package-updater/internal/protocol"
|
||||
)
|
||||
|
||||
func TestDiff(t *testing.T) {
|
||||
a := protocol.Service{Kind: protocol.KindContainer, ContainerName: "a", Image: "a:1", Status: "running"}
|
||||
b := protocol.Service{Kind: protocol.KindContainer, ContainerName: "b", Image: "b:1", Status: "running"}
|
||||
bStopped := b
|
||||
bStopped.Status = "stopped"
|
||||
c := protocol.Service{Kind: protocol.KindContainer, ContainerName: "c", Image: "c:1", Status: "running"}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
prev, next []protocol.Service
|
||||
wantUpserts []protocol.Service
|
||||
wantRemoves []string
|
||||
}{
|
||||
{"unchanged", []protocol.Service{a, b}, []protocol.Service{a, b}, nil, nil},
|
||||
{"added", []protocol.Service{a}, []protocol.Service{a, c}, []protocol.Service{c}, nil},
|
||||
{"changed", []protocol.Service{a, b}, []protocol.Service{a, bStopped}, []protocol.Service{bStopped}, nil},
|
||||
{"removed", []protocol.Service{a, b}, []protocol.Service{a}, nil, []string{"container|b"}},
|
||||
{"from empty", nil, []protocol.Service{a}, []protocol.Service{a}, nil},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ups, rms := Diff(tc.prev, tc.next)
|
||||
assert.Equal(t, tc.wantUpserts, ups)
|
||||
assert.Equal(t, tc.wantRemoves, rms)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user