Skip to content

Commit

Permalink
Adjust kubectl-workspace tests for diagnostic information output on s…
Browse files Browse the repository at this point in the history
…tderr

Signed-off-by: Marvin Beckers <[email protected]>
  • Loading branch information
embik committed May 16, 2024
1 parent 94aa1ea commit 2c4396c
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions cli/pkg/workspace/plugin/use_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestUse(t *testing.T) {

expected *clientcmdapi.Config
wantStdout []string
wantStderr []string
wantErrors []string
wantErr bool
noWarn bool
Expand Down Expand Up @@ -451,7 +452,10 @@ func TestUse(t *testing.T) {
param: "",
expected: NewKubeconfig().WithKcpCurrent(homeWorkspace.String()).WithKcpPrevious("root:foo").Build(),
destination: homeWorkspace.String(),
wantStdout: []string{fmt.Sprintf("Current workspace is '%s'.\nNote: 'kubectl ws' now matches 'cd' semantics: go to home workspace. 'kubectl ws -' to go back. 'kubectl ws .' to print current workspace.", homeWorkspace.String())},
wantStderr: []string{
"Note: 'kubectl ws' now matches 'cd' semantics: go to home workspace. 'kubectl ws -' to go back. 'kubectl ws .' to print current workspace.",
},
wantStdout: []string{fmt.Sprintf("Current workspace is '%s'.", homeWorkspace.String())},
},
{
name: "workspace name, apibindings have matching permission and export claims",
Expand Down Expand Up @@ -488,9 +492,10 @@ func TestUse(t *testing.T) {
WithExportClaim("", "configmaps", "").
Build(),
},
wantStdout: []string{
wantStderr: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
"Current workspace is 'root:foo:bar'"},
},
wantStdout: []string{"Current workspace is 'root:foo:bar'"},
},
{
name: "~, apibinding claims/exports don't match",
Expand All @@ -509,8 +514,10 @@ func TestUse(t *testing.T) {
WithExportClaim("", "configmaps", "").
Build(),
},
wantStderr: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.",
},
wantStdout: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
fmt.Sprintf("Current workspace is '%s'", homeWorkspace.String())},
},
{
Expand All @@ -529,8 +536,10 @@ func TestUse(t *testing.T) {
WithExportClaim("", "configmaps", "").
Build(),
},
wantStderr: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.",
},
wantStdout: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
"Current workspace is 'root:foo:bar'"},
},
{
Expand Down Expand Up @@ -590,8 +599,10 @@ func TestUse(t *testing.T) {
WithExportClaim("", "configmaps", "").
Build(),
},
wantStderr: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.",
},
wantStdout: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
"Current workspace is 'root:foo:bar'"},
},
{
Expand All @@ -610,8 +621,10 @@ func TestUse(t *testing.T) {
WithExportClaim("test.kcp.io", "test", "abcdef").
Build(),
},
wantStderr: []string{
"Warning: claim for test.test.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.",
},
wantStdout: []string{
"Warning: claim for test.test.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.\n",
"Current workspace is 'root:foo:bar'"},
},
{
Expand All @@ -631,9 +644,11 @@ func TestUse(t *testing.T) {
WithExportClaim("", "configmaps", "").
Build(),
},
wantStderr: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.",
"Warning: claim for test.test.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.",
},
wantStdout: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
"Warning: claim for test.test.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.\n",
"Current workspace is 'root:foo:bar'"},
},
{
Expand All @@ -654,10 +669,11 @@ func TestUse(t *testing.T) {
WithExportClaim("test2.kcp.io", "test2", "abcdef").
Build(),
},
wantStdout: []string{
"Warning: claim for test.test.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.\n",
"Warning: claim for test2.test2.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.\n",
"Current workspace is 'root:foo:bar'"},
wantStderr: []string{
"Warning: claim for test.test.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.",
"Warning: claim for test2.test2.kcp.io:abcdef specified on APIBinding a but not accepted or rejected.",
},
wantStdout: []string{"Current workspace is 'root:foo:bar'"},
},
{
name: "workspace name, multiple APIBindings unspecified",
Expand All @@ -675,10 +691,11 @@ func TestUse(t *testing.T) {
WithExportClaim("", "configmaps", "").
Build(),
},
wantStdout: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
"Warning: claim for test.test.kcp.io:abcdef exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.\n",
"Current workspace is 'root:foo:bar'"},
wantStderr: []string{
"Warning: claim for configmaps exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.",
"Warning: claim for test.test.kcp.io:abcdef exported but not specified on APIBinding a\nAdd this claim to the APIBinding's Spec.",
},
wantStdout: []string{"Current workspace is 'root:foo:bar'"},
},
{
name: "relative change multiple jumps from non root",
Expand Down Expand Up @@ -836,7 +853,10 @@ func TestUse(t *testing.T) {
require.Contains(t, stdout.String(), s)
}
if tt.noWarn {
require.NotContains(t, stdout.String(), "Warning")
require.NotContains(t, stderr.String(), "Warning")
}
for _, s := range tt.wantStderr {
require.Contains(t, stderr.String(), s)
}
if err != nil {
for _, s := range tt.wantErrors {
Expand Down

0 comments on commit 2c4396c

Please sign in to comment.