pod-volume-cleaner/pkg/cleaner/cleaner_test.go

51 lines
1.2 KiB
Go

package cleaner
import (
"github.com/cyrilix/pod-cleaner/pkg/monitor"
"testing"
)
func TestPodWatcher_Watch(t *testing.T) {
type fields struct {
logfile string
}
tests := []struct {
name string
fields fields
wantPodDir string
wantNumError int
}{
{
name: "one error in file",
fields: fields{
logfile: "test_data/one-error.log",
},
wantPodDir: "/var/lib/kubelet/pods/1d4bfc07-3469-4eaa-992f-6d23c17f3aee",
wantNumError: 1,
},
{
name: "no error",
fields: fields{
logfile: "test_data/no-error.log",
},
wantPodDir: "",
wantNumError: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := NewPodWatcher(tt.fields.logfile)
w.m = monitor.New(monitor.WithTailFollow(false), monitor.WithReOpen(false))
w.Watch()
gotNumErr := w.GetNumErrors()
if gotNumErr != tt.wantNumError {
t.Errorf("PodWatcher_Watch(), bad numErrors found: %v, want %v", gotNumErr, tt.wantNumError)
}
gotPodDir := w.GetPodDirInError()
if gotPodDir != tt.wantPodDir {
t.Errorf("PodWatcher_Watch(), bad pod directory found: %v, want %v", gotPodDir, tt.wantPodDir)
}
})
}
}