@@ -15,6 +15,7 @@ import (
15
15
"github.com/coder/coder/v2/coderd/database/dbtime"
16
16
"github.com/coder/coder/v2/coderd/provisionerdserver"
17
17
"github.com/coder/coder/v2/coderd/telemetry"
18
+ "github.com/coder/coder/v2/provisionersdk/proto"
18
19
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
19
20
)
20
21
@@ -30,10 +31,31 @@ func CreateWorkspace(t testing.TB, db database.Store, seed database.Workspace) d
30
31
CreatedBy : seed .OwnerID ,
31
32
})
32
33
seed .TemplateID = template .ID
34
+ seed .OwnerID = template .CreatedBy
35
+ seed .OrganizationID = template .OrganizationID
33
36
}
34
37
return dbgen .Workspace (t , db , seed )
35
38
}
36
39
40
+ // CreateWorkspaceWithAgent is a helper that generates a workspace with a single resource
41
+ // that has an agent attached to it. The agent token is returned.
42
+ func CreateWorkspaceWithAgent (t testing.TB , db database.Store , seed database.Workspace ) (database.Workspace , string ) {
43
+ t .Helper ()
44
+ authToken := uuid .NewString ()
45
+ ws := CreateWorkspace (t , db , seed )
46
+ CreateWorkspaceBuild (t , db , ws , database.WorkspaceBuild {}, & proto.Resource {
47
+ Name : "example" ,
48
+ Type : "aws_instance" ,
49
+ Agents : []* proto.Agent {{
50
+ Id : uuid .NewString (),
51
+ Auth : & proto.Agent_Token {
52
+ Token : authToken ,
53
+ },
54
+ }},
55
+ })
56
+ return ws , authToken
57
+ }
58
+
37
59
// CreateWorkspaceBuild inserts a build and a successful job into the database.
38
60
func CreateWorkspaceBuild (t testing.TB , db database.Store , ws database.Workspace , seed database.WorkspaceBuild , resources ... * sdkproto.Resource ) database.WorkspaceBuild {
39
61
t .Helper ()
@@ -43,9 +65,28 @@ func CreateWorkspaceBuild(t testing.TB, db database.Store, ws database.Workspace
43
65
// This intentionally fulfills the minimum requirements of the schema.
44
66
// Tests can provide a custom version ID if necessary.
45
67
if seed .TemplateVersionID == uuid .Nil {
68
+ jobID := uuid .New ()
46
69
templateVersion := dbgen .TemplateVersion (t , db , database.TemplateVersion {
70
+ JobID : jobID ,
47
71
OrganizationID : ws .OrganizationID ,
48
72
CreatedBy : ws .OwnerID ,
73
+ TemplateID : uuid.NullUUID {
74
+ UUID : ws .TemplateID ,
75
+ Valid : true ,
76
+ },
77
+ })
78
+ payload , _ := json .Marshal (provisionerdserver.TemplateVersionImportJob {
79
+ TemplateVersionID : templateVersion .ID ,
80
+ })
81
+ dbgen .ProvisionerJob (t , db , nil , database.ProvisionerJob {
82
+ ID : jobID ,
83
+ OrganizationID : ws .OrganizationID ,
84
+ Input : payload ,
85
+ Type : database .ProvisionerJobTypeTemplateVersionImport ,
86
+ CompletedAt : sql.NullTime {
87
+ Time : dbtime .Now (),
88
+ Valid : true ,
89
+ },
49
90
})
50
91
seed .TemplateVersionID = templateVersion .ID
51
92
}
0 commit comments