(t *testing.T)
| 33 | } |
| 34 | |
| 35 | func 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 | { |
nothing calls this directly
no test coverage detected