Skip to content

Commit

Permalink
chore: update config tests
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
  • Loading branch information
rustatian committed Aug 15, 2023
1 parent 00d24df commit 80f2569
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
21 changes: 14 additions & 7 deletions container/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ func TestNewConfig_SuccessfulReading(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, c)

ll, err := container.ParseLogLevel(c.LogLevel)
assert.NoError(t, err)

assert.Equal(t, time.Second*10, c.GracePeriod)
assert.True(t, c.PrintGraph)
assert.Equal(t, slog.LevelWarn, c.LogLevel)
assert.Equal(t, slog.LevelWarn, ll.Level())
}

func TestNewConfig_WithoutEndureKey(t *testing.T) {
Expand All @@ -28,9 +31,12 @@ func TestNewConfig_WithoutEndureKey(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, c)

ll, err := container.ParseLogLevel(c.LogLevel)
assert.NoError(t, err)

assert.Equal(t, time.Second*30, c.GracePeriod)
assert.False(t, c.PrintGraph)
assert.Equal(t, slog.LevelError, c.LogLevel)
assert.Equal(t, slog.LevelError, ll.Level())
}

func TestNewConfig_LoggingLevels(t *testing.T) {
Expand All @@ -53,15 +59,16 @@ func TestNewConfig_LoggingLevels(t *testing.T) {
assert.NoError(t, cfgPlugin.Init())

c, err := container.NewConfig(tt.path)
assert.NotNil(t, c)
ll, err2 := container.ParseLogLevel(c.LogLevel)

if tt.wantError {
assert.Nil(t, c)
assert.Error(t, err)
assert.Contains(t, err.Error(), "unknown log level")
assert.Error(t, err2)
assert.Contains(t, err2.Error(), "unknown log level")
} else {
assert.NoError(t, err)
assert.NotNil(t, c)
assert.Equal(t, tt.wantLevel, c.LogLevel)
assert.NoError(t, err2)
assert.Equal(t, tt.wantLevel, ll.Level())
}
})
}
Expand Down
14 changes: 13 additions & 1 deletion internal/sdnotify/sdnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@ func StartWatchdog(interval int, stopCh chan struct{}) {
case <-stopCh:
return
case <-ticker.C:
_, _ = SdNotify(Watchdog)
supported, err := SdNotify(Watchdog)
if err != nil {
// notification supported, but failure happened, retry
continue
}
// notification not supported, stop
if !supported && err == nil {
return
}
// notification supported, data has been sent, continue
if supported && err == nil {
continue
}
}
}
}()
Expand Down

0 comments on commit 80f2569

Please sign in to comment.