7
7
"errors"
8
8
"fmt"
9
9
"sort"
10
- "sync/atomic"
11
10
"testing"
12
11
"time"
13
12
@@ -4711,13 +4710,11 @@ func TestGetPresetsAtFailureLimit(t *testing.T) {
4711
4710
func TestWorkspaceAgentNameUniqueTrigger (t * testing.T ) {
4712
4711
t .Parallel ()
4713
4712
4714
- var builds atomic.Int32
4715
-
4716
4713
if ! dbtestutil .WillUsePostgres () {
4717
4714
t .Skip ("This test makes use of a database trigger not implemented in dbmem" )
4718
4715
}
4719
4716
4720
- createWorkspaceWithAgent := func (t * testing.T , db database.Store , org database.Organization , agentName string ) (database.WorkspaceTable , database.TemplateVersion , database.WorkspaceAgent ) {
4717
+ createWorkspaceWithAgent := func (t * testing.T , db database.Store , org database.Organization , agentName string ) (database.WorkspaceTable , database.WorkspaceResource , database.WorkspaceAgent ) {
4721
4718
t .Helper ()
4722
4719
4723
4720
user := dbgen .User (t , db , database.User {})
@@ -4740,7 +4737,7 @@ func TestWorkspaceAgentNameUniqueTrigger(t *testing.T) {
4740
4737
OrganizationID : org .ID ,
4741
4738
})
4742
4739
build := dbgen .WorkspaceBuild (t , db , database.WorkspaceBuild {
4743
- BuildNumber : builds . Add ( 1 ) ,
4740
+ BuildNumber : 1 ,
4744
4741
JobID : job .ID ,
4745
4742
WorkspaceID : workspace .ID ,
4746
4743
TemplateVersionID : templateVersion .ID ,
@@ -4753,40 +4750,27 @@ func TestWorkspaceAgentNameUniqueTrigger(t *testing.T) {
4753
4750
Name : agentName ,
4754
4751
})
4755
4752
4756
- return workspace , templateVersion , agent
4753
+ return workspace , resource , agent
4757
4754
}
4758
4755
4759
- t .Run ("DuplicateNamesInSameWorkspace " , func (t * testing.T ) {
4756
+ t .Run ("DuplicateNamesInSameWorkspaceBuild " , func (t * testing.T ) {
4760
4757
t .Parallel ()
4761
4758
4762
4759
db , _ := dbtestutil .NewDB (t )
4763
4760
org := dbgen .Organization (t , db , database.Organization {})
4764
4761
ctx := testutil .Context (t , testutil .WaitShort )
4765
4762
4766
4763
// Given: A workspace with an agent
4767
- workspace1 , templateVersion1 , agent1 := createWorkspaceWithAgent (t , db , org , "duplicate-agent" )
4768
- require .Equal (t , "duplicate-agent" , agent1 .Name )
4764
+ _ , resource , agent := createWorkspaceWithAgent (t , db , org , "duplicate-agent" )
4765
+ require .Equal (t , "duplicate-agent" , agent .Name )
4769
4766
4770
4767
// When: Another agent is created for that workspace with the same name.
4771
- job2 := dbgen .ProvisionerJob (t , db , nil , database.ProvisionerJob {
4772
- Type : database .ProvisionerJobTypeWorkspaceBuild ,
4773
- OrganizationID : org .ID ,
4774
- })
4775
- build2 := dbgen .WorkspaceBuild (t , db , database.WorkspaceBuild {
4776
- BuildNumber : builds .Add (1 ),
4777
- JobID : job2 .ID ,
4778
- WorkspaceID : workspace1 .ID ,
4779
- TemplateVersionID : templateVersion1 .ID ,
4780
- })
4781
- resource2 := dbgen .WorkspaceResource (t , db , database.WorkspaceResource {
4782
- JobID : build2 .JobID ,
4783
- })
4784
4768
_ , err := db .InsertWorkspaceAgent (ctx , database.InsertWorkspaceAgentParams {
4785
4769
ID : uuid .New (),
4786
4770
CreatedAt : time .Now (),
4787
4771
UpdatedAt : time .Now (),
4788
4772
Name : "duplicate-agent" , // Same name as agent1
4789
- ResourceID : resource2 .ID ,
4773
+ ResourceID : resource .ID ,
4790
4774
AuthToken : uuid .New (),
4791
4775
Architecture : "amd64" ,
4792
4776
OperatingSystem : "linux" ,
@@ -4798,7 +4782,7 @@ func TestWorkspaceAgentNameUniqueTrigger(t *testing.T) {
4798
4782
var pqErr * pq.Error
4799
4783
require .True (t , errors .As (err , & pqErr ))
4800
4784
require .Equal (t , pq .ErrorCode ("23505" ), pqErr .Code ) // unique_violation
4801
- require .Contains (t , pqErr .Message , `workspace agent name "duplicate-agent" already exists in this workspace` )
4785
+ require .Contains (t , pqErr .Message , `workspace agent name "duplicate-agent" already exists in this workspace resource ` )
4802
4786
})
4803
4787
4804
4788
t .Run ("SameNamesInDifferentWorkspaces" , func (t * testing.T ) {
0 commit comments