MCPcopy
hub / github.com/cli/cli / Test_EnableRepoOverride_authCheckIntegration

Function Test_EnableRepoOverride_authCheckIntegration

pkg/cmdutil/repo_override_test.go:20–70  ·  view source on GitHub ↗

Test_EnableRepoOverride_authCheckIntegration is an integration test for the coupling between repo override and the root auth gate, wired through cobra's persistent pre-run hooks. EnableRepoOverride replaces a command's PersistentPreRunE, so cobra no longer reaches the root auth gate on its own; the

(t *testing.T)

Source from the content-addressed store, hash-verified

18// This pins that a leaf's DisableAuthCheck is honored under a repo-override
19// parent.
20func Test_EnableRepoOverride_authCheckIntegration(t *testing.T) {
21 tests := []struct {
22 name string
23 disableAuthLeaf bool
24 wantAuthChecked bool
25 }{
26 {
27 name: "leaf opts out, honored under repo-override parent",
28 disableAuthLeaf: true,
29 wantAuthChecked: false,
30 },
31 {
32 name: "leaf does not opt out, auth still checked",
33 disableAuthLeaf: false,
34 wantAuthChecked: true,
35 },
36 }
37
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 var gotAuthChecked, ranLeaf bool
41
42 // Stand in for the real root auth gate: it judges whatever command
43 // it is handed, so it must receive the invoked leaf command.
44 root := &cobra.Command{Use: "root"}
45 root.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
46 gotAuthChecked = IsAuthCheckEnabled(cmd)
47 return nil
48 }
49
50 parent := &cobra.Command{Use: "parent"}
51 EnableRepoOverride(parent, &Factory{})
52 root.AddCommand(parent)
53
54 leaf := &cobra.Command{
55 Use: "leaf",
56 RunE: func(cmd *cobra.Command, args []string) error { ranLeaf = true; return nil },
57 }
58 if tt.disableAuthLeaf {
59 DisableAuthCheck(leaf)
60 }
61 parent.AddCommand(leaf)
62
63 root.SetArgs([]string{"parent", "leaf"})
64 require.NoError(t, root.Execute())
65
66 require.True(t, ranLeaf, "leaf command should have executed")
67 require.Equal(t, tt.wantAuthChecked, gotAuthChecked)
68 })
69 }
70}

Callers

nothing calls this directly

Calls 5

IsAuthCheckEnabledFunction · 0.85
EnableRepoOverrideFunction · 0.85
DisableAuthCheckFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected