-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix namespace suggestion error on context switch
- Loading branch information
Showing
3 changed files
with
54 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of K9s | ||
|
||
package view | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_suggestSubCommand(t *testing.T) { | ||
namespaceNames := []string{"kube-system", "kube-public", "default", "nginx-ingress"} | ||
contextNames := []string{"develop", "test", "pre", "prod"} | ||
|
||
tests := []struct { | ||
Command string | ||
Suggestions []string | ||
}{ | ||
{Command: "q", Suggestions: nil}, | ||
{Command: "xray dp", Suggestions: nil}, | ||
{Command: "help k", Suggestions: nil}, | ||
{Command: "ctx p", Suggestions: []string{"re", "rod"}}, | ||
{Command: "ctx p", Suggestions: []string{"re", "rod"}}, | ||
{Command: "ctx pr", Suggestions: []string{"e", "od"}}, | ||
{Command: "context d", Suggestions: []string{"evelop"}}, | ||
{Command: "contexts t", Suggestions: []string{"est"}}, | ||
{Command: "po ", Suggestions: nil}, | ||
{Command: "po x", Suggestions: nil}, | ||
{Command: "po k", Suggestions: []string{"ube-system", "ube-public"}}, | ||
{Command: "po kube-", Suggestions: []string{"system", "public"}}, | ||
} | ||
|
||
for _, tt := range tests { | ||
got := suggestSubCommand(tt.Command, namespaceNames, contextNames) | ||
assert.Equal(t, tt.Suggestions, got) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of K9s | ||
|
||
package view | ||
package view_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/derailed/k9s/internal/config" | ||
"github.com/derailed/k9s/internal/view" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAppNew(t *testing.T) { | ||
a := NewApp(config.NewConfig(ks{})) | ||
a := view.NewApp(config.NewConfig(ks{})) | ||
_ = a.Init("blee", 10) | ||
|
||
assert.Equal(t, 11, len(a.GetActions())) | ||
} | ||
|
||
func Test_suggestSubCommand(t *testing.T) { | ||
namespaceNames := []string{"kube-system", "kube-public", "default", "nginx-ingress"} | ||
contextNames := []string{"develop", "test", "pre", "prod"} | ||
|
||
tests := []struct { | ||
Command string | ||
Suggestions []string | ||
}{ | ||
{Command: "q", Suggestions: nil}, | ||
{Command: "xray dp", Suggestions: nil}, | ||
{Command: "help k", Suggestions: nil}, | ||
{Command: "ctx p", Suggestions: []string{"re", "rod"}}, | ||
{Command: "ctx p", Suggestions: []string{"re", "rod"}}, | ||
{Command: "ctx pr", Suggestions: []string{"e", "od"}}, | ||
{Command: "context d", Suggestions: []string{"evelop"}}, | ||
{Command: "contexts t", Suggestions: []string{"est"}}, | ||
{Command: "po ", Suggestions: nil}, | ||
{Command: "po x", Suggestions: nil}, | ||
{Command: "po k", Suggestions: []string{"ube-system", "ube-public"}}, | ||
{Command: "po kube-", Suggestions: []string{"system", "public"}}, | ||
} | ||
|
||
for _, tt := range tests { | ||
got := suggestSubCommand(tt.Command, namespaceNames, contextNames) | ||
assert.Equal(t, tt.Suggestions, got) | ||
} | ||
} |