Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ microcks context http://localhost:8080 --delete`,
}

ctxName := args[0]
errors.CheckConfigNil(localCfg == nil, configPath)
if localCfg.CurrentContext == ctxName {
fmt.Printf("Already at context '%s'\n", localCfg.CurrentContext)
return
Expand Down Expand Up @@ -100,9 +101,7 @@ func deleteContext(context, configPath string) error {
func printMicrocksContexts(configPath string) {
localCfg, err := config.ReadLocalConfig(configPath)
errors.CheckError(err)
if localCfg == nil {
log.Fatalf("No contexts defined in %s", configPath)
}
errors.CheckConfigNil(localCfg == nil, configPath)
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
defer func() { _ = w.Flush() }()
columnNames := []string{"CURRENT", "NAME", "SERVER"}
Expand Down
6 changes: 6 additions & 0 deletions cmd/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ func TestDeleteContext(t *testing.T) {
_, err = config.ReadLocalConfig(testConfigFilePath)
require.NoError(t, err)
}

func TestDeleteContextEmpty(t *testing.T) {
err := deleteContext("http://localhost:8080", "./testdata/non-existent-file.config")
require.EqualError(t, err, "Nothing to logout from")
}

7 changes: 7 additions & 0 deletions pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func CheckError(err error) {
}
}

func CheckConfigNil(isNil bool, path string) {
if isNil {
Fatal(ErrorGeneric, "No contexts defined in "+path)
}
}


// Fatal is a wrapper for log.Fatal() to exit with custom code
func Fatal(exitcode int, args ...interface{}) {
log.Println(args...)
Expand Down
Loading