1
1
package cli_test
2
2
3
3
import (
4
+ "fmt"
4
5
"testing"
5
6
6
7
"github.com/stretchr/testify/require"
@@ -44,6 +45,7 @@ func TestCreate(t *testing.T) {
44
45
}
45
46
<- doneChan
46
47
})
48
+
47
49
t .Run ("CreateFromList" ,func (t * testing.T ) {
48
50
t .Parallel ()
49
51
client := coderdtest .New (t ,nil )
@@ -74,6 +76,7 @@ func TestCreate(t *testing.T) {
74
76
}
75
77
<- doneChan
76
78
})
79
+
77
80
t .Run ("FromNothing" ,func (t * testing.T ) {
78
81
t .Parallel ()
79
82
client := coderdtest .New (t ,nil )
@@ -105,33 +108,52 @@ func TestCreate(t *testing.T) {
105
108
}
106
109
<- doneChan
107
110
})
111
+
108
112
t .Run ("WithParameter" ,func (t * testing.T ) {
109
113
t .Parallel ()
110
114
client := coderdtest .New (t ,nil )
111
115
user := coderdtest .CreateFirstUser (t ,client )
112
116
coderdtest .NewProvisionerDaemon (t ,client )
117
+
118
+ defaultValue := "something"
113
119
version := coderdtest .CreateTemplateVersion (t ,client ,user .OrganizationID ,& echo.Responses {
114
120
Parse : []* proto.Parse_Response {{
115
121
Type :& proto.Parse_Response_Complete {
116
122
Complete :& proto.Parse_Complete {
117
- ParameterSchemas : []* proto.ParameterSchema {{
118
- AllowOverrideSource :true ,
119
- Name :"region" ,
120
- Description :"description" ,
121
- DefaultSource :& proto.ParameterSource {
122
- Scheme :proto .ParameterSource_DATA ,
123
- Value :"something" ,
123
+ ParameterSchemas : []* proto.ParameterSchema {
124
+ {
125
+ AllowOverrideSource :true ,
126
+ Name :"region" ,
127
+ Description :"description 1" ,
128
+ DefaultSource :& proto.ParameterSource {
129
+ Scheme :proto .ParameterSource_DATA ,
130
+ Value :defaultValue ,
131
+ },
132
+ DefaultDestination :& proto.ParameterDestination {
133
+ Scheme :proto .ParameterDestination_PROVISIONER_VARIABLE ,
134
+ },
124
135
},
125
- DefaultDestination :& proto.ParameterDestination {
126
- Scheme :proto .ParameterDestination_PROVISIONER_VARIABLE ,
136
+ {
137
+ AllowOverrideSource :true ,
138
+ Name :"username" ,
139
+ Description :"description 2" ,
140
+ DefaultSource :& proto.ParameterSource {
141
+ Scheme :proto .ParameterSource_DATA ,
142
+ // No default value
143
+ Value :"" ,
144
+ },
145
+ DefaultDestination :& proto.ParameterDestination {
146
+ Scheme :proto .ParameterDestination_PROVISIONER_VARIABLE ,
147
+ },
127
148
},
128
- }} ,
149
+ },
129
150
},
130
151
},
131
152
}},
132
153
Provision :echo .ProvisionComplete ,
133
154
ProvisionDryRun :echo .ProvisionComplete ,
134
155
})
156
+
135
157
coderdtest .AwaitTemplateVersionJob (t ,client ,version .ID )
136
158
_ = coderdtest .CreateTemplate (t ,client ,user .OrganizationID ,version .ID )
137
159
cmd ,root := clitest .New (t ,"create" ,"" )
@@ -145,9 +167,11 @@ func TestCreate(t *testing.T) {
145
167
err := cmd .Execute ()
146
168
require .NoError (t ,err )
147
169
}()
170
+
148
171
matches := []string {
149
172
"Specify a name" ,"my-workspace" ,
150
- "Enter a value" ,"bananas" ,
173
+ fmt .Sprintf ("Enter a value (default: %q):" ,defaultValue ),"bingo" ,
174
+ "Enter a value:" ,"boingo" ,
151
175
"Confirm create?" ,"yes" ,
152
176
}
153
177
for i := 0 ;i < len (matches );i += 2 {