@@ -182,7 +182,6 @@ func TestDBAuthzRecursive(t *testing.T) {
182
182
method .Name == "PGLocks" {
183
183
continue
184
184
}
185
- // Log the name of the last method, so if there is a panic, it is
186
185
// easy to know which method failed.
187
186
// t.Log(method.Name)
188
187
// Call the function. Any infinite recursion will stack overflow.
@@ -969,8 +968,7 @@ func (s *MethodTestSuite) TestOrganization() {
969
968
TemplateVersionID : workspaceBuild .TemplateVersionID ,
970
969
Name : "test" ,
971
970
}
972
- preset , err := db .InsertPreset (context .Background (), insertPresetParams )
973
- require .NoError (s .T (), err )
971
+ preset := dbgen .Preset (s .T (), db , insertPresetParams )
974
972
insertPresetParametersParams := database.InsertPresetParametersParams {
975
973
TemplateVersionPresetID : preset .ID ,
976
974
Names : []string {"test" },
@@ -1027,8 +1025,8 @@ func (s *MethodTestSuite) TestOrganization() {
1027
1025
})
1028
1026
1029
1027
check .Args (database.OrganizationMembersParams {
1030
- OrganizationID : uuid. UUID {} ,
1031
- UserID : uuid. UUID {} ,
1028
+ OrganizationID : o . ID ,
1029
+ UserID : u . ID ,
1032
1030
}).Asserts (
1033
1031
mem , policy .ActionRead ,
1034
1032
)
@@ -3906,96 +3904,6 @@ func (s *MethodTestSuite) TestSystemFunctions() {
3906
3904
ErrorsWithInMemDB (sql .ErrNoRows ).
3907
3905
Returns ([]database.ParameterSchema {})
3908
3906
}))
3909
- s .Run ("GetPresetByWorkspaceBuildID" , s .Subtest (func (db database.Store , check * expects ) {
3910
- org := dbgen .Organization (s .T (), db , database.Organization {})
3911
- user := dbgen .User (s .T (), db , database.User {})
3912
- template := dbgen .Template (s .T (), db , database.Template {
3913
- CreatedBy : user .ID ,
3914
- OrganizationID : org .ID ,
3915
- })
3916
- templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
3917
- TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
3918
- OrganizationID : org .ID ,
3919
- CreatedBy : user .ID ,
3920
- })
3921
- preset , err := db .InsertPreset (context .Background (), database.InsertPresetParams {
3922
- TemplateVersionID : templateVersion .ID ,
3923
- Name : "test" ,
3924
- })
3925
- require .NoError (s .T (), err )
3926
- workspace := dbgen .Workspace (s .T (), db , database.WorkspaceTable {
3927
- OrganizationID : org .ID ,
3928
- OwnerID : user .ID ,
3929
- TemplateID : template .ID ,
3930
- })
3931
- job := dbgen .ProvisionerJob (s .T (), db , nil , database.ProvisionerJob {
3932
- OrganizationID : org .ID ,
3933
- })
3934
- workspaceBuild := dbgen .WorkspaceBuild (s .T (), db , database.WorkspaceBuild {
3935
- WorkspaceID : workspace .ID ,
3936
- TemplateVersionID : templateVersion .ID ,
3937
- TemplateVersionPresetID : uuid.NullUUID {UUID : preset .ID , Valid : true },
3938
- InitiatorID : user .ID ,
3939
- JobID : job .ID ,
3940
- })
3941
- _ , err = db .GetPresetByWorkspaceBuildID (context .Background (), workspaceBuild .ID )
3942
- require .NoError (s .T (), err )
3943
- check .Args (workspaceBuild .ID ).Asserts (rbac .ResourceTemplate , policy .ActionRead )
3944
- }))
3945
- s .Run ("GetPresetParametersByTemplateVersionID" , s .Subtest (func (db database.Store , check * expects ) {
3946
- ctx := context .Background ()
3947
- org := dbgen .Organization (s .T (), db , database.Organization {})
3948
- user := dbgen .User (s .T (), db , database.User {})
3949
- template := dbgen .Template (s .T (), db , database.Template {
3950
- CreatedBy : user .ID ,
3951
- OrganizationID : org .ID ,
3952
- })
3953
- templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
3954
- TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
3955
- OrganizationID : org .ID ,
3956
- CreatedBy : user .ID ,
3957
- })
3958
- preset , err := db .InsertPreset (ctx , database.InsertPresetParams {
3959
- TemplateVersionID : templateVersion .ID ,
3960
- Name : "test" ,
3961
- })
3962
- require .NoError (s .T (), err )
3963
- _ , err = db .InsertPresetParameters (ctx , database.InsertPresetParametersParams {
3964
- TemplateVersionPresetID : preset .ID ,
3965
- Names : []string {"test" },
3966
- Values : []string {"test" },
3967
- })
3968
- require .NoError (s .T (), err )
3969
- presetParameters , err := db .GetPresetParametersByTemplateVersionID (ctx , templateVersion .ID )
3970
- require .NoError (s .T (), err )
3971
-
3972
- check .Args (templateVersion .ID ).Asserts (template .RBACObject (), policy .ActionRead ).Returns (presetParameters )
3973
- }))
3974
- s .Run ("GetPresetsByTemplateVersionID" , s .Subtest (func (db database.Store , check * expects ) {
3975
- ctx := context .Background ()
3976
- org := dbgen .Organization (s .T (), db , database.Organization {})
3977
- user := dbgen .User (s .T (), db , database.User {})
3978
- template := dbgen .Template (s .T (), db , database.Template {
3979
- CreatedBy : user .ID ,
3980
- OrganizationID : org .ID ,
3981
- })
3982
- templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
3983
- TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
3984
- OrganizationID : org .ID ,
3985
- CreatedBy : user .ID ,
3986
- })
3987
-
3988
- _ , err := db .InsertPreset (ctx , database.InsertPresetParams {
3989
- TemplateVersionID : templateVersion .ID ,
3990
- Name : "test" ,
3991
- })
3992
- require .NoError (s .T (), err )
3993
-
3994
- presets , err := db .GetPresetsByTemplateVersionID (ctx , templateVersion .ID )
3995
- require .NoError (s .T (), err )
3996
-
3997
- check .Args (templateVersion .ID ).Asserts (template .RBACObject (), policy .ActionRead ).Returns (presets )
3998
- }))
3999
3907
s .Run ("GetWorkspaceAppsByAgentIDs" , s .Subtest (func (db database.Store , check * expects ) {
4000
3908
dbtestutil .DisableForeignKeysAndTriggers (s .T (), db )
4001
3909
aWs := dbgen .Workspace (s .T (), db , database.WorkspaceTable {})
@@ -4839,6 +4747,125 @@ func (s *MethodTestSuite) TestNotifications() {
4839
4747
}
4840
4748
4841
4749
func (s * MethodTestSuite ) TestPrebuilds () {
4750
+ s .Run ("GetPresetByWorkspaceBuildID" , s .Subtest (func (db database.Store , check * expects ) {
4751
+ org := dbgen .Organization (s .T (), db , database.Organization {})
4752
+ user := dbgen .User (s .T (), db , database.User {})
4753
+ template := dbgen .Template (s .T (), db , database.Template {
4754
+ CreatedBy : user .ID ,
4755
+ OrganizationID : org .ID ,
4756
+ })
4757
+ templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
4758
+ TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
4759
+ OrganizationID : org .ID ,
4760
+ CreatedBy : user .ID ,
4761
+ })
4762
+ preset , err := db .InsertPreset (context .Background (), database.InsertPresetParams {
4763
+ TemplateVersionID : templateVersion .ID ,
4764
+ Name : "test" ,
4765
+ })
4766
+ require .NoError (s .T (), err )
4767
+ workspace := dbgen .Workspace (s .T (), db , database.WorkspaceTable {
4768
+ OrganizationID : org .ID ,
4769
+ OwnerID : user .ID ,
4770
+ TemplateID : template .ID ,
4771
+ })
4772
+ job := dbgen .ProvisionerJob (s .T (), db , nil , database.ProvisionerJob {
4773
+ OrganizationID : org .ID ,
4774
+ })
4775
+ workspaceBuild := dbgen .WorkspaceBuild (s .T (), db , database.WorkspaceBuild {
4776
+ WorkspaceID : workspace .ID ,
4777
+ TemplateVersionID : templateVersion .ID ,
4778
+ TemplateVersionPresetID : uuid.NullUUID {UUID : preset .ID , Valid : true },
4779
+ InitiatorID : user .ID ,
4780
+ JobID : job .ID ,
4781
+ })
4782
+ _ , err = db .GetPresetByWorkspaceBuildID (context .Background (), workspaceBuild .ID )
4783
+ require .NoError (s .T (), err )
4784
+ check .Args (workspaceBuild .ID ).Asserts (rbac .ResourceTemplate , policy .ActionRead )
4785
+ }))
4786
+ s .Run ("GetPresetParametersByTemplateVersionID" , s .Subtest (func (db database.Store , check * expects ) {
4787
+ ctx := context .Background ()
4788
+ org := dbgen .Organization (s .T (), db , database.Organization {})
4789
+ user := dbgen .User (s .T (), db , database.User {})
4790
+ template := dbgen .Template (s .T (), db , database.Template {
4791
+ CreatedBy : user .ID ,
4792
+ OrganizationID : org .ID ,
4793
+ })
4794
+ templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
4795
+ TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
4796
+ OrganizationID : org .ID ,
4797
+ CreatedBy : user .ID ,
4798
+ })
4799
+ preset , err := db .InsertPreset (ctx , database.InsertPresetParams {
4800
+ TemplateVersionID : templateVersion .ID ,
4801
+ Name : "test" ,
4802
+ })
4803
+ require .NoError (s .T (), err )
4804
+ insertedParameters , err := db .InsertPresetParameters (ctx , database.InsertPresetParametersParams {
4805
+ TemplateVersionPresetID : preset .ID ,
4806
+ Names : []string {"test" },
4807
+ Values : []string {"test" },
4808
+ })
4809
+ require .NoError (s .T (), err )
4810
+ check .
4811
+ Args (templateVersion .ID ).
4812
+ Asserts (template .RBACObject (), policy .ActionRead ).
4813
+ Returns (insertedParameters )
4814
+ }))
4815
+ s .Run ("GetPresetParametersByPresetID" , s .Subtest (func (db database.Store , check * expects ) {
4816
+ ctx := context .Background ()
4817
+ org := dbgen .Organization (s .T (), db , database.Organization {})
4818
+ user := dbgen .User (s .T (), db , database.User {})
4819
+ template := dbgen .Template (s .T (), db , database.Template {
4820
+ CreatedBy : user .ID ,
4821
+ OrganizationID : org .ID ,
4822
+ })
4823
+ templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
4824
+ TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
4825
+ OrganizationID : org .ID ,
4826
+ CreatedBy : user .ID ,
4827
+ })
4828
+ preset , err := db .InsertPreset (ctx , database.InsertPresetParams {
4829
+ TemplateVersionID : templateVersion .ID ,
4830
+ Name : "test" ,
4831
+ })
4832
+ require .NoError (s .T (), err )
4833
+ insertedParameters , err := db .InsertPresetParameters (ctx , database.InsertPresetParametersParams {
4834
+ TemplateVersionPresetID : preset .ID ,
4835
+ Names : []string {"test" },
4836
+ Values : []string {"test" },
4837
+ })
4838
+ require .NoError (s .T (), err )
4839
+ check .
4840
+ Args (preset .ID ).
4841
+ Asserts (template .RBACObject (), policy .ActionRead ).
4842
+ Returns (insertedParameters )
4843
+ }))
4844
+ s .Run ("GetPresetsByTemplateVersionID" , s .Subtest (func (db database.Store , check * expects ) {
4845
+ ctx := context .Background ()
4846
+ org := dbgen .Organization (s .T (), db , database.Organization {})
4847
+ user := dbgen .User (s .T (), db , database.User {})
4848
+ template := dbgen .Template (s .T (), db , database.Template {
4849
+ CreatedBy : user .ID ,
4850
+ OrganizationID : org .ID ,
4851
+ })
4852
+ templateVersion := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
4853
+ TemplateID : uuid.NullUUID {UUID : template .ID , Valid : true },
4854
+ OrganizationID : org .ID ,
4855
+ CreatedBy : user .ID ,
4856
+ })
4857
+
4858
+ _ , err := db .InsertPreset (ctx , database.InsertPresetParams {
4859
+ TemplateVersionID : templateVersion .ID ,
4860
+ Name : "test" ,
4861
+ })
4862
+ require .NoError (s .T (), err )
4863
+
4864
+ presets , err := db .GetPresetsByTemplateVersionID (ctx , templateVersion .ID )
4865
+ require .NoError (s .T (), err )
4866
+
4867
+ check .Args (templateVersion .ID ).Asserts (template .RBACObject (), policy .ActionRead ).Returns (presets )
4868
+ }))
4842
4869
s .Run ("ClaimPrebuiltWorkspace" , s .Subtest (func (db database.Store , check * expects ) {
4843
4870
org := dbgen .Organization (s .T (), db , database.Organization {})
4844
4871
user := dbgen .User (s .T (), db , database.User {})
@@ -4923,7 +4950,8 @@ func (s *MethodTestSuite) TestPrebuilds() {
4923
4950
UUID : template .ID ,
4924
4951
Valid : true ,
4925
4952
},
4926
- OrganizationID : org .ID ,
4953
+ InvalidateAfterSecs : preset .InvalidateAfterSecs ,
4954
+ OrganizationID : org .ID ,
4927
4955
})
4928
4956
}))
4929
4957
}
0 commit comments