Skip to content

Commit

Permalink
re-run
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Jan 10, 2024
1 parent bb6785d commit 378352c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
11 changes: 11 additions & 0 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
errUnsupportedAerospikeVersion = fmt.Errorf("aerospike version unsupported")
errInvalidOutput = fmt.Errorf("invalid output flag")
errInvalidFormat = fmt.Errorf("invalid format flag")
errMissingFormat = fmt.Errorf("missing format flag")
)

func init() {
Expand Down Expand Up @@ -252,6 +253,16 @@ func newConvertCmd() *cobra.Command {
}
}

formatString, err := cmd.Flags().GetString("format")
if err != nil {
return errors.Join(errMissingFormat, err)
}

_, err = ParseFmtString(formatString)
if err != nil && formatString != "" {
return errors.Join(errInvalidFormat, err)
}

return nil
},
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package cmd
import (
"errors"
"testing"

"github.com/aerospike/asconfig/conf"
)

type preTestConvert struct {
Expand Down Expand Up @@ -45,6 +47,20 @@ var preTestsConvert = []preTestConvert{
arguments: []string{"./convert_test.go"},
expectedErrors: []error{nil},
},
{
flags: []string{"--format", "bad_fmt"},
arguments: []string{"./convert_test.go"},
expectedErrors: []error{
conf.ErrInvalidFormat,
},
},
{
flags: []string{"-F", "bad_fmt"},
arguments: []string{"./convert_test.go"},
expectedErrors: []error{
conf.ErrInvalidFormat,
},
},
}

func TestPreRunConvert(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions cmd/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ var testDiffArgs = []runTestDiff{
arguments: []string{"../testdata/expected/all_flash_cluster_cr.conf", "../testdata/expected/all_flash_cluster_cr.conf"},
expectError: false,
},
{
flags: []string{"--format", "bad_fmt"},
arguments: []string{},
expectError: true,
},
{
flags: []string{"-F", "bad_fmt"},
arguments: []string{},
expectError: true,
},
}

func TestRunEDiff(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func newRootCmd() *cobra.Command {

lvlCode, err := logrus.ParseLevel(lvl)
if err != nil {
logger.Errorf("Invalid log-level %s", lvl)
multiErr = fmt.Errorf("%w, %w %w", multiErr, errInvalidLogLevel, err)
// logger.Errorf("Invalid log-level %s", lvl)
multiErr = errors.Join(multiErr, errInvalidLogLevel, err)
}

logger.SetLevel(lvlCode)
Expand Down
20 changes: 1 addition & 19 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//go:build unit

package cmd

import (
"errors"
"testing"

"github.com/aerospike/asconfig/conf"
)

type preTestRoot struct {
Expand All @@ -33,20 +29,6 @@ var preTestsRoot = []preTestRoot{
errInvalidLogLevel,
},
},
{
flags: []string{"--format", "bad_fmt"},
arguments: []string{},
expectedErrors: []error{
conf.ErrInvalidFormat,
},
},
{
flags: []string{"-F", "bad_fmt"},
arguments: []string{},
expectedErrors: []error{
conf.ErrInvalidFormat,
},
},
}

func TestPersistentPreRunRoot(t *testing.T) {
Expand All @@ -57,7 +39,7 @@ func TestPersistentPreRunRoot(t *testing.T) {
err := cmd.PersistentPreRunE(cmd, test.arguments)
for _, expectedErr := range test.expectedErrors {
if !errors.Is(err, expectedErr) {
t.Errorf("actual err: %v\n is not expected err: %v", err, expectedErr)
t.Errorf("%v\n actual err: %v\n is not expected err: %v", test.flags, err, expectedErr)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ var testValidateArgs = []runTestValidate{
arguments: []string{"../testdata/cases/server70/server70.conf"},
expectError: false,
},
{
flags: []string{"--format", "bad_fmt"},
arguments: []string{},
expectError: true,
},
{
flags: []string{"-F", "bad_fmt"},
arguments: []string{},
expectError: true,
},
}

func TestRunEValidate(t *testing.T) {
Expand Down

0 comments on commit 378352c

Please sign in to comment.