@@ -15,6 +15,75 @@ import (
15
15
"github.com/coder/coder/v2/scaletest/workspacebuild"
16
16
)
17
17
18
+ func Test_UserConfig (t * testing.T ) {
19
+ t .Parallel ()
20
+
21
+ id := uuid .New ()
22
+
23
+ cases := []struct {
24
+ name string
25
+ config createworkspaces.UserConfig
26
+ errContains string
27
+ }{
28
+ {
29
+ name :"OK" ,
30
+ config : createworkspaces.UserConfig {
31
+ OrganizationID :id ,
32
+ Username :"test" ,
33
+ Email :"test@test.coder.com" ,
34
+ },
35
+ },
36
+ {
37
+ name :"NoOrganizationID" ,
38
+ config : createworkspaces.UserConfig {
39
+ OrganizationID :uuid .Nil ,
40
+ Username :"test" ,
41
+ Email :"test@test.coder.com" ,
42
+ },
43
+ errContains :"organization_id must not be a nil UUID" ,
44
+ },
45
+ {
46
+ name :"OKSessionToken" ,
47
+ config : createworkspaces.UserConfig {
48
+ OrganizationID :id ,
49
+ SessionToken :"sometoken" ,
50
+ },
51
+ },
52
+ {
53
+ name :"WithSessionTokenAndUsername" ,
54
+ config : createworkspaces.UserConfig {
55
+ OrganizationID :id ,
56
+ Username :"test" ,
57
+ SessionToken :"sometoken" ,
58
+ },
59
+ errContains :"username must be empty when session_token is set" ,
60
+ },
61
+ {
62
+ name :"WithSessionTokenAndEmail" ,
63
+ config : createworkspaces.UserConfig {
64
+ OrganizationID :id ,
65
+ Email :"test@test.coder.com" ,
66
+ SessionToken :"sometoken" ,
67
+ },
68
+ errContains :"email must be empty when session_token is set" ,
69
+ },
70
+ }
71
+
72
+ for _ ,c := range cases {
73
+ t .Run (c .name ,func (t * testing.T ) {
74
+ t .Parallel ()
75
+
76
+ err := c .config .Validate ()
77
+ if c .errContains != "" {
78
+ require .Error (t ,err )
79
+ require .Contains (t ,err .Error (),c .errContains )
80
+ }else {
81
+ require .NoError (t ,err )
82
+ }
83
+ })
84
+ }
85
+ }
86
+
18
87
func Test_Config (t * testing.T ) {
19
88
t .Parallel ()
20
89