MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / TestLogin_ApiKey

Function TestLogin_ApiKey

pkg/cmd/login/login_test.go:21–259  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19var rootResource = testutil.NewRootResource()
20
21func 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

Callers

nothing calls this directly

Calls 14

GetCurrentHostMethod · 0.95
GoBegin2Function · 0.92
ReceivePairFunction · 0.92
NewMockServerAndAskerFunction · 0.92
NewAskProviderFunction · 0.92
NewMockFactoryFunction · 0.92
AnswerWithMethod · 0.80
ExpectQuestionMethod · 0.80
RespondWithMethod · 0.80
ExpectRequestMethod · 0.80
RespondWithErrorMethod · 0.80
AsAskerMethod · 0.80

Tested by

no test coverage detected