extract number of errors and pod directory

This commit is contained in:
cyrilix committed 2022-09-07 20:09:49 +02:00
1 parent 95f86d69f4
commit 620cef3310
6 files changed
+174 -5

No files matched your search

+49
View File
@@ -1 +1,50 @@
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)
}
})
}
}