Skip to content

Commit

Permalink
Update error message for context not found
Browse files Browse the repository at this point in the history
  • Loading branch information
anujc25 committed Dec 20, 2023
1 parent 450decc commit 5d84d5c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions config/context_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ currentContext:
err = DeleteContext("test-mc2")
assert.NoError(t, err)
ctx, err = GetContext("test-mc2")
assert.Equal(t, "context test-mc2 not found", err.Error())
assert.Equal(t, "context \"test-mc2\" not found", err.Error())
assert.Nil(t, ctx)
}
func TestContextsServersSyncWhenNoContextsExist(t *testing.T) {
Expand Down Expand Up @@ -189,7 +189,7 @@ currentContext:
// Get Context
context, err := GetContext("test-mc")
assert.Nil(t, context)
assert.Equal(t, "context test-mc not found", err.Error())
assert.Equal(t, "context \"test-mc\" not found", err.Error())

// Add new Server
newServer := &configtypes.Server{
Expand Down Expand Up @@ -235,6 +235,6 @@ currentContext:
err = DeleteContext("test-mc2")
assert.NoError(t, err)
ctx, err = GetContext("test-mc2")
assert.Equal(t, "context test-mc2 not found", err.Error())
assert.Equal(t, "context \"test-mc2\" not found", err.Error())
assert.Nil(t, ctx)
}
2 changes: 1 addition & 1 deletion config/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func getContext(node *yaml.Node, name string) (*configtypes.Context, error) {
return ctx, nil
}
}
return nil, fmt.Errorf("context %v not found", name)
return nil, fmt.Errorf("context %q not found", name)
}

func getActiveContext(node *yaml.Node, contextType configtypes.ContextType) (*configtypes.Context, error) {
Expand Down
2 changes: 1 addition & 1 deletion config/contexts_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,6 @@ func TestContextsIntegration(t *testing.T) {
err = DeleteContext("test-mc2")
assert.NoError(t, err)
ctx, err = GetContext("test-mc2")
assert.Equal(t, "context test-mc2 not found", err.Error())
assert.Equal(t, "context \"test-mc2\" not found", err.Error())
assert.Nil(t, ctx)
}
10 changes: 5 additions & 5 deletions config/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSetGetDeleteContext(t *testing.T) {
}

ctx, err := GetContext("test1")
assert.Equal(t, "context test1 not found", err.Error())
assert.Equal(t, "context \"test1\" not found", err.Error())
assert.Nil(t, ctx)

err = SetContext(ctx1, true)
Expand All @@ -100,14 +100,14 @@ func TestSetGetDeleteContext(t *testing.T) {
assert.Equal(t, ctx1, ctx)

err = DeleteContext("test")
assert.Equal(t, "context test not found", err.Error())
assert.Equal(t, "context \"test\" not found", err.Error())

err = DeleteContext("test1")
assert.Nil(t, err)

ctx, err = GetContext("test1")
assert.Nil(t, ctx)
assert.Equal(t, "context test1 not found", err.Error())
assert.Equal(t, "context \"test1\" not found", err.Error())
}

func TestSetContextWithOldVersion(t *testing.T) {
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestGetContext(t *testing.T) {
{
name: "failure",
ctxName: "test",
errStr: "context test not found",
errStr: "context \"test\" not found",
},
}

Expand Down Expand Up @@ -872,7 +872,7 @@ func TestRemoveContext(t *testing.T) {
{
name: "failure",
ctxName: "test",
errStr: "context test not found",
errStr: "context \"test\" not found",
},
}

Expand Down
2 changes: 1 addition & 1 deletion config/tanzu_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestGetTanzuContextActiveResource(t *testing.T) {
// Test getting the Tanzu active resource of a non-existent context
_, err = GetTanzuContextActiveResource("non-existent-context")
assert.Error(t, err)
assert.ErrorContains(t, err, "context non-existent-context not found")
assert.ErrorContains(t, err, "context \"non-existent-context\" not found")

// Test getting the Tanzu active resource of a context that is not Tanzu context
_, err = GetTanzuContextActiveResource("test-mc")
Expand Down
6 changes: 3 additions & 3 deletions test/compatibility/framework/context/context_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func GetContextCommand(opts ...CfgContextArgsOption) *core.Command {
if args.Error {
outputOpts = &GetContextOutputOptions{
RuntimeAPIVersion: args.RuntimeAPIVersion,
Error: fmt.Sprintf("context %v not found", args.ContextName),
Error: fmt.Sprintf("context %q not found", args.ContextName),
}
} else {
outputOpts = &GetContextOutputOptions{
Expand All @@ -121,7 +121,7 @@ func GetContextCommand(opts ...CfgContextArgsOption) *core.Command {
if args.Error {
outputOpts = &GetContextOutputOptions{
RuntimeAPIVersion: args.RuntimeAPIVersion,
Error: fmt.Sprintf("context %v not found", args.ContextName),
Error: fmt.Sprintf("context %q not found", args.ContextName),
}
} else {
outputOpts = &GetContextOutputOptions{
Expand Down Expand Up @@ -189,7 +189,7 @@ func DeleteContextCommand(opts ...CfgContextArgsOption) *core.Command {
case core.VersionLatest, core.Version102, core.Version090, core.Version0280:
outputOpts = &DeleteContextOutputOptions{
RuntimeAPIVersion: args.RuntimeAPIVersion,
Error: fmt.Sprintf("context %v not found", args.ContextName),
Error: fmt.Sprintf("context %q not found", args.ContextName),
}
case core.Version0254:
outputOpts = &DeleteContextOutputOptions{
Expand Down
4 changes: 2 additions & 2 deletions test/compatibility/framework/server/server_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func DeleteServerCommand(opts ...CfgServerArgsOption) *core.Command {
case core.VersionLatest, core.Version102, core.Version090, core.Version0280, core.Version0254, core.Version0116:
outputOpts = &DeleteServerOutputOptions{
RuntimeAPIVersion: args.RuntimeAPIVersion,
Error: fmt.Sprintf("context %v not found", args.ServerName),
Error: fmt.Sprintf("context %q not found", args.ServerName),
}
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func RemoveCurrentServerCommand(opts ...CfgServerArgsOption) *core.Command {
case core.VersionLatest, core.Version102, core.Version090, core.Version0280, core.Version0254, core.Version0116:
outputOpts = &RemoveCurrentServerOutputOptions{
RuntimeAPIVersion: args.RuntimeAPIVersion,
Error: fmt.Sprintf("context %v not found", args.ServerName),
Error: fmt.Sprintf("context %q not found", args.ServerName),
}
}
}
Expand Down

0 comments on commit 5d84d5c

Please sign in to comment.