mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-01 21:02:33 +00:00
Refactor CLI to be a thin adapter over the library
- util/cli.go: RunMark() now maps CLI flags into mark.Config and delegates to mark.Run(); all core processing logic removed - util/cli_test.go: absorb Test_setLogLevel from deleted main_test.go - main.go, main_test.go: removed (entry point is now cmd/mark/main.go) - Makefile: update build target to ./cmd/mark with -o mark Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/reconquest/pkg/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
@@ -74,3 +76,44 @@ func TestContentAppearanceFlagValidation(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_setLogLevel(t *testing.T) {
|
||||
type args struct {
|
||||
lvl string
|
||||
}
|
||||
tests := map[string]struct {
|
||||
args args
|
||||
want log.Level
|
||||
expectedErr string
|
||||
}{
|
||||
"invalid": {args: args{lvl: "INVALID"}, want: log.LevelInfo, expectedErr: "unknown log level: INVALID"},
|
||||
"empty": {args: args{lvl: ""}, want: log.LevelInfo, expectedErr: "unknown log level: "},
|
||||
"info": {args: args{lvl: log.LevelInfo.String()}, want: log.LevelInfo},
|
||||
"debug": {args: args{lvl: log.LevelDebug.String()}, want: log.LevelDebug},
|
||||
"trace": {args: args{lvl: log.LevelTrace.String()}, want: log.LevelTrace},
|
||||
"warning": {args: args{lvl: log.LevelWarning.String()}, want: log.LevelWarning},
|
||||
"error": {args: args{lvl: log.LevelError.String()}, want: log.LevelError},
|
||||
"fatal": {args: args{lvl: log.LevelFatal.String()}, want: log.LevelFatal},
|
||||
}
|
||||
for name, tt := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
cmd := &cli.Command{
|
||||
Name: "test",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "log-level",
|
||||
Value: tt.args.lvl,
|
||||
Usage: "set the log level. Possible values: TRACE, DEBUG, INFO, WARNING, ERROR, FATAL.",
|
||||
},
|
||||
},
|
||||
}
|
||||
err := SetLogLevel(cmd)
|
||||
if tt.expectedErr != "" {
|
||||
assert.EqualError(t, err, tt.expectedErr)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, log.GetLevel())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user