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

Function TestAskVariables

pkg/executionscommon/executionscommon_test.go:18–356  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestAskVariables(t *testing.T) {
19 const spaceID = "Spaces-1"
20 const fireProjectID = "Projects-22"
21
22 makeVariables := func(variables ...*variables.Variable) *variables.VariableSet {
23 vars := fixtures.NewVariableSetForProject(spaceID, fireProjectID)
24 vars.ID = fmt.Sprintf("%s-s-0-2ZFWS", vars.ID)
25 vars.Variables = variables
26 return vars
27 }
28
29 tests := []struct {
30 name string
31 run func(t *testing.T, qa *testutil.AskMocker, stdout *bytes.Buffer)
32 }{
33 {"doesn't do anything if there are no variables", func(t *testing.T, qa *testutil.AskMocker, stdout *bytes.Buffer) {
34 output, err := executionscommon.AskVariables(qa.AsAsker(), makeVariables(), make(map[string]string, 0))
35 assert.Nil(t, err)
36 assert.Equal(t, make(map[string]string, 0), output)
37 }},
38
39 {"variablesFromCmd are filtered and normalized against the server", func(t *testing.T, qa *testutil.AskMocker, stdout *bytes.Buffer) {
40 serverVars := makeVariables(variables.NewVariable("Foo"))
41 cmdlineVars := map[string]string{"foO": "bar", "doesntexist": "value"}
42
43 output, err := executionscommon.AskVariables(qa.AsAsker(), serverVars, cmdlineVars)
44 assert.Nil(t, err)
45 assert.Equal(t, map[string]string{"Foo": "bar"}, output)
46 }},
47
48 {"prompts for a single line text", func(t *testing.T, qa *testutil.AskMocker, stdout *bytes.Buffer) {
49 v1 := variables.NewVariable("SomeText")
50 v1.Prompt = &variables.VariablePromptOptions{
51 Description: "Enter some text",
52 DisplaySettings: nil,
53 IsRequired: false,
54 Label: "ignored",
55 }
56
57 vars := makeVariables(v1)
58 receiver := testutil.GoBegin2(func() (map[string]string, error) {
59 return executionscommon.AskVariables(qa.AsAsker(), vars, make(map[string]string, 0))
60 })
61
62 _ = qa.ExpectQuestion(t, &survey.Input{
63 Message: "SomeText (Enter some text)",
64 Default: "",
65 }).AnswerWith("Some Value")
66
67 output, err := testutil.ReceivePair(receiver)
68 assert.Nil(t, err)
69 assert.Equal(t, map[string]string{"SomeText": "Some Value"}, output)
70 }},
71
72 {"single line text with default value", func(t *testing.T, qa *testutil.AskMocker, stdout *bytes.Buffer) {
73 v1 := variables.NewVariable("SomeText")
74 v1.Value = "Some Default Value"
75 v1.Prompt = &variables.VariablePromptOptions{

Callers

nothing calls this directly

Calls 9

AsAskerMethod · 0.95
ExpectQuestionMethod · 0.95
NewVariableSetForProjectFunction · 0.92
AskVariablesFunction · 0.92
GoBegin2Function · 0.92
ReceivePairFunction · 0.92
NewAskMockerFunction · 0.92
AnswerWithMethod · 0.80

Tested by

no test coverage detected