Skip to content

Commit

Permalink
test refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
  • Loading branch information
Pavel Okhlopkov committed Nov 5, 2024
1 parent 5632157 commit ae7be71
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/utils/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

log "github.com/deckhouse/deckhouse/pkg/log"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -123,8 +124,15 @@ func TestRecursiveCheckLibDirectory(t *testing.T) {

logger := log.NewLogger(log.Options{
Output: &buf,
TimeFunc: func(_ time.Time) time.Time {
parsedTime, err := time.Parse(time.DateTime, "2006-01-02 15:04:05")
if err != nil {
assert.NoError(t, err)
}

return parsedTime
},
})
logger = logger.With("time", "0:0:0")

log.SetDefault(logger)

Expand All @@ -133,9 +141,9 @@ func TestRecursiveCheckLibDirectory(t *testing.T) {
t.Errorf("RecursiveCheckLibDirectory() error = %v, wantErr %v", err, tt.wantErr)
}

assert.Contains(t,
strings.TrimSpace(buf.String()),
`File '/lib.py' has executable permissions and is located in the ignored 'lib' directory`)
assert.Equal(t,
buf.String(),
`{"level":"warn","msg":"File '/lib.py' has executable permissions and is located in the ignored 'lib' directory","time":"2006-01-02T15:04:05Z"}`+"\n")
})
}

Expand Down

0 comments on commit ae7be71

Please sign in to comment.