1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

chore: adds tests cases back

This commit is contained in:
Amir Raminfar
2025-02-12 17:02:24 -08:00
parent 9e028b9916
commit b7e9871382

View File

@@ -70,6 +70,52 @@ func TestContainerStore_List(t *testing.T) {
assert.Equal(t, containers[0].ID, "1234")
}
func TestContainerStore_die(t *testing.T) {
client := new(mockedClient)
client.On("ListContainers", mock.Anything, mock.Anything).Return([]Container{
{
ID: "1234",
Name: "test",
State: "running",
Stats: utils.NewRingBuffer[ContainerStat](300),
},
}, nil)
client.On("ContainerEvents", mock.Anything, mock.AnythingOfType("chan<- container.ContainerEvent")).Return(nil).
Run(func(args mock.Arguments) {
ctx := args.Get(0).(context.Context)
events := args.Get(1).(chan<- ContainerEvent)
events <- ContainerEvent{
Name: "die",
ActorID: "1234",
Host: "localhost",
}
<-ctx.Done()
})
client.On("Host").Return(Host{
ID: "localhost",
})
client.On("ContainerStats", mock.Anything, "1234", mock.AnythingOfType("chan<- container.ContainerStat")).Return(nil)
client.On("FindContainer", mock.Anything, "1234").Return(Container{
ID: "1234",
Name: "test",
Image: "test",
Stats: utils.NewRingBuffer[ContainerStat](300),
}, nil)
store := NewContainerStore(t.Context(), client, &fakeStatsCollector{}, ContainerLabels{})
// Wait until we get the event
events := make(chan ContainerEvent)
store.SubscribeEvents(t.Context(), events)
<-events
containers, _ := store.ListContainers(ContainerLabels{})
assert.Equal(t, containers[0].State, "exited")
}
type fakeStatsCollector struct{}
func (f *fakeStatsCollector) Subscribe(_ context.Context, _ chan<- ContainerStat) {}