Skip to content

Commit 59fc9b9

Browse files
authored
Add additional check for pod and node watcher unit test (#193)
* Add extra check for Pod and Node watcher unit test * Remove cooments * go format of file
1 parent 0269458 commit 59fc9b9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

internal/monitor/monitor_steps_test.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ type feature struct {
7777
maxNodeAPILoopTimes int
7878
// If true and the test case has expected loghook.LastEntry set to
7979
//'none', it will validate if it indeed was a successful message.
80-
validateLastMessage bool
81-
badWatchObject bool
82-
utilMock *utils.Mock
80+
validateLastMessage bool
81+
badWatchObject bool
82+
utilMock *utils.Mock
83+
validateWatcherMessage bool
8384
}
8485

8586
func (f *feature) aControllerMonitorUnity() error {
@@ -355,7 +356,18 @@ func (f *feature) theLastLogMessageContains(errormsg string) error {
355356
return fmt.Errorf("expected error message to contain: %s, but last log entry was nil", errormsg)
356357
} else if strings.Contains(lastEntry.Message, errormsg) {
357358
return nil
359+
} else if f.validateWatcherMessage {
360+
possibleLastMsg := []string{
361+
"PodMonitor.Mode not set", "PodWatcher stopped...", "Setup of PodWatcher complete", "node name: node1",
362+
"Setup of NodeWatcher complete", "NodeWatcher stopped...", "labelSelector:", "attempting to start",
363+
}
364+
for _, msg := range possibleLastMsg {
365+
if strings.Contains(lastEntry.Message, msg) {
366+
return nil
367+
}
368+
}
358369
}
370+
359371
return fmt.Errorf("expected error message to contain: %s, but it was %s", errormsg, lastEntry.Message)
360372
}
361373

@@ -752,6 +764,7 @@ func (f *feature) iCallAPIMonitorLoop(nodeName string) error {
752764
func (f *feature) iCallStartPodMonitorWithKeyAndValue(key, value string) error {
753765
MonitorRestartTimeDelay = 5 * time.Millisecond
754766
client := fake.NewSimpleClientset()
767+
f.validateWatcherMessage = true
755768
go StartPodMonitor(K8sAPI, client, key, value, MonitorRestartTimeDelay)
756769
return nil
757770
}
@@ -792,6 +805,7 @@ func (f *feature) podMonitorMode(mode string) error {
792805
func (f *feature) iCallStartNodeMonitorWithKeyAndValue(key, value string) error {
793806
MonitorRestartTimeDelay = 5 * time.Millisecond
794807
client := fake.NewSimpleClientset()
808+
f.validateWatcherMessage = true
795809
go StartNodeMonitor(K8sAPI, client, key, value, MonitorRestartTimeDelay)
796810
return nil
797811
}

0 commit comments

Comments
 (0)