(t *testing.T)
| 34 | } |
| 35 | |
| 36 | func TestCompleteContextNames(t *testing.T) { |
| 37 | allNames := []string{"context-b", "context-c", "context-a"} |
| 38 | cli := &fakeContextProvider{ |
| 39 | contextStore: fakeContextStore{ |
| 40 | names: allNames, |
| 41 | }, |
| 42 | } |
| 43 | |
| 44 | t.Run("with limit", func(t *testing.T) { |
| 45 | compFunc := completeContextNames(cli, 1, false) |
| 46 | values, directives := compFunc(nil, nil, "") |
| 47 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) |
| 48 | assert.Check(t, is.DeepEqual(values, allNames)) |
| 49 | |
| 50 | values, directives = compFunc(nil, []string{"context-c"}, "") |
| 51 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) |
| 52 | assert.Check(t, is.Len(values, 0)) |
| 53 | }) |
| 54 | |
| 55 | t.Run("with limit and file completion", func(t *testing.T) { |
| 56 | compFunc := completeContextNames(cli, 1, true) |
| 57 | values, directives := compFunc(nil, nil, "") |
| 58 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) |
| 59 | assert.Check(t, is.DeepEqual(values, allNames)) |
| 60 | |
| 61 | values, directives = compFunc(nil, []string{"context-c"}, "") |
| 62 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveDefault), "should provide filenames completion after limit") |
| 63 | assert.Check(t, is.Len(values, 0)) |
| 64 | }) |
| 65 | |
| 66 | t.Run("without limits", func(t *testing.T) { |
| 67 | compFunc := completeContextNames(cli, -1, false) |
| 68 | values, directives := compFunc(nil, []string{"context-c"}, "") |
| 69 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) |
| 70 | assert.Check(t, is.DeepEqual(values, []string{"context-b", "context-a"}), "should not contain already completed") |
| 71 | |
| 72 | values, directives = compFunc(nil, []string{"context-c", "context-a"}, "") |
| 73 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp)) |
| 74 | assert.Check(t, is.DeepEqual(values, []string{"context-b"}), "should not contain already completed") |
| 75 | |
| 76 | values, directives = compFunc(nil, []string{"context-c", "context-a", "context-b"}, "") |
| 77 | assert.Check(t, is.Equal(directives, cobra.ShellCompDirectiveNoFileComp), "should provide filenames completion after limit") |
| 78 | assert.Check(t, is.Len(values, 0)) |
| 79 | }) |
| 80 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…