(t *testing.T)
| 19 | var rootResource = testutil.NewRootResource() |
| 20 | |
| 21 | func TestLogin_ApiKey(t *testing.T) { |
| 22 | tests := []struct { |
| 23 | name string |
| 24 | run func(t *testing.T, fac *testutil.MockFactory, api *testutil.MockHttpServer, qa *testutil.AskMocker, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) |
| 25 | }{ |
| 26 | {"interactive: configures server and api key correctly", func(t *testing.T, fac *testutil.MockFactory, api *testutil.MockHttpServer, qa *testutil.AskMocker, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) { |
| 27 | currentHost := fac.GetCurrentHost() |
| 28 | apiKey := "API-APIKEY01" |
| 29 | |
| 30 | cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) { |
| 31 | defer api.Close() |
| 32 | rootCmd.SetArgs([]string{"login"}) |
| 33 | return rootCmd.ExecuteC() |
| 34 | }) |
| 35 | |
| 36 | _ = qa.ExpectQuestion(t, &survey.Input{ |
| 37 | Message: "Octopus Server URL", |
| 38 | }).AnswerWith(currentHost) |
| 39 | |
| 40 | _ = qa.ExpectQuestion(t, &survey.Confirm{ |
| 41 | Message: "Create a new API key", |
| 42 | Default: true, |
| 43 | }).AnswerWith(false) |
| 44 | |
| 45 | _ = qa.ExpectQuestion(t, &survey.Input{ |
| 46 | Message: "API Key", |
| 47 | }).AnswerWith(apiKey) |
| 48 | |
| 49 | user := users.NewUser("test", "Test") |
| 50 | |
| 51 | api.ExpectRequest(t, "GET", "/api/").RespondWith(rootResource) |
| 52 | api.ExpectRequest(t, "GET", "/api/spaces").RespondWith(rootResource) |
| 53 | |
| 54 | api.ExpectRequest(t, "GET", "/api/users/me").RespondWith(user) |
| 55 | |
| 56 | _, err := testutil.ReceivePair(cmdReceiver) |
| 57 | assert.Nil(t, err) |
| 58 | |
| 59 | assert.Equal(t, currentHost, fac.ConfigProvider.Get(constants.ConfigUrl)) |
| 60 | assert.Equal(t, apiKey, fac.ConfigProvider.Get(constants.ConfigApiKey)) |
| 61 | assert.Empty(t, fac.ConfigProvider.Get(constants.ConfigAccessToken)) |
| 62 | }}, |
| 63 | |
| 64 | {"interactive: uses server if supplied", func(t *testing.T, fac *testutil.MockFactory, api *testutil.MockHttpServer, qa *testutil.AskMocker, rootCmd *cobra.Command, stdOut *bytes.Buffer, stdErr *bytes.Buffer) { |
| 65 | currentHost := fac.GetCurrentHost() |
| 66 | apiKey := "API-APIKEY01" |
| 67 | |
| 68 | cmdReceiver := testutil.GoBegin2(func() (*cobra.Command, error) { |
| 69 | defer api.Close() |
| 70 | rootCmd.SetArgs([]string{"login", "--server", currentHost}) |
| 71 | return rootCmd.ExecuteC() |
| 72 | }) |
| 73 | |
| 74 | _ = qa.ExpectQuestion(t, &survey.Confirm{ |
| 75 | Message: "Create a new API key", |
| 76 | Default: true, |
| 77 | }).AnswerWith(false) |
| 78 |
nothing calls this directly
no test coverage detected