MCPcopy
hub / github.com/cli/cli / TestNewCmdAgentTask

Function TestNewCmdAgentTask

pkg/cmd/agent-task/agent_task_test.go:35–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestNewCmdAgentTask(t *testing.T) {
36 tests := []struct {
37 name string
38 tokenSource string
39 customConfig func() (gh.Config, error)
40 wantErr bool
41 wantErrContains string
42 wantStdout string
43 }{
44 {
45 name: "oauth token is accepted",
46 tokenSource: "oauth_token",
47 wantErr: false,
48 wantStdout: "",
49 },
50 {
51 name: "keyring oauth token is accepted",
52 tokenSource: "keyring",
53 wantErr: false,
54 wantStdout: "",
55 },
56 {
57 name: "env var token is rejected",
58 tokenSource: "GH_TOKEN",
59 wantErr: true,
60 wantErrContains: "requires an OAuth token",
61 },
62 {
63 name: "enterprise token alone is ignored and rejected",
64 tokenSource: "GH_ENTERPRISE_TOKEN",
65 wantErr: true,
66 },
67 {
68 name: "github.com oauth is accepted and enterprise token ignored",
69 customConfig: func() (gh.Config, error) {
70 c := config.NewBlankConfig()
71 c.Set("something.ghes.com", "oauth_token", "ghe_ENTERPRISE123")
72 c.Set("github.com", "oauth_token", "gho_OAUTH123")
73 return c, nil
74 },
75 wantErr: false,
76 wantStdout: "",
77 },
78 {
79 name: "enterprise host is rejected",
80 customConfig: func() (gh.Config, error) {
81 return &ghmock.ConfigMock{
82 AuthenticationFunc: func() gh.AuthConfig {
83 c := &config.AuthConfig{}
84 c.SetDefaultHost("something.ghes.com", "GH_HOST")
85 return c
86 },
87 }, nil
88 },
89 wantErr: true,
90 wantErrContains: "not supported on this host",
91 },
92 {

Callers

nothing calls this directly

Calls 11

SetDefaultHostMethod · 0.95
NewBlankConfigFunction · 0.92
TestFunction · 0.92
setupMockOAuthConfigFunction · 0.85
NewCmdAgentTaskFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
SetMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected