@@ -293,6 +293,7 @@ func TestUpdater_createPeerUpdate(t *testing.T) {
293
293
ctx : ctx ,
294
294
netLoopDone : make (chan struct {}),
295
295
agents : map [uuid.UUID ]tailnet.Agent {},
296
+ workspaces : map [uuid.UUID ]tailnet.Workspace {},
296
297
conn : newFakeConn (tailnet.WorkspaceUpdate {}, hsTime ),
297
298
}
298
299
@@ -727,6 +728,7 @@ func TestProcessFreshState(t *testing.T) {
727
728
wsID1 := uuid .New ()
728
729
wsID2 := uuid .New ()
729
730
wsID3 := uuid .New ()
731
+ wsID4 := uuid .New ()
730
732
731
733
agentID1 := uuid .New ()
732
734
agentID2 := uuid .New ()
@@ -738,25 +740,32 @@ func TestProcessFreshState(t *testing.T) {
738
740
agent3 := tailnet.Agent {ID : agentID3 , Name : "agent3" , WorkspaceID : wsID3 }
739
741
agent4 := tailnet.Agent {ID : agentID4 , Name : "agent4" , WorkspaceID : wsID1 }
740
742
741
- ws1 := tailnet.Workspace {ID : wsID1 , Name : "ws1" }
742
- ws2 := tailnet.Workspace {ID : wsID2 , Name : "ws2" }
743
- ws3 := tailnet.Workspace {ID : wsID3 , Name : "ws3" }
743
+ ws1 := tailnet.Workspace {ID : wsID1 , Name : "ws1" , Status : proto .Workspace_RUNNING }
744
+ ws2 := tailnet.Workspace {ID : wsID2 , Name : "ws2" , Status : proto .Workspace_RUNNING }
745
+ ws3 := tailnet.Workspace {ID : wsID3 , Name : "ws3" , Status : proto .Workspace_RUNNING }
746
+ ws4 := tailnet.Workspace {ID : wsID4 , Name : "ws4" , Status : proto .Workspace_RUNNING }
744
747
745
748
initialAgents := map [uuid.UUID ]tailnet.Agent {
746
749
agentID1 : agent1 ,
747
750
agentID2 : agent2 ,
748
751
agentID4 : agent4 ,
749
752
}
753
+ initialWorkspaces := map [uuid.UUID ]tailnet.Workspace {
754
+ wsID1 : ws1 ,
755
+ wsID2 : ws2 ,
756
+ }
750
757
751
758
tests := []struct {
752
- name string
753
- initialAgents map [uuid.UUID ]tailnet.Agent
754
- update * tailnet.WorkspaceUpdate
755
- expectedDelete * tailnet.WorkspaceUpdate // We only care about deletions added by the function
759
+ name string
760
+ initialAgents map [uuid.UUID ]tailnet.Agent
761
+ initialWorkspaces map [uuid.UUID ]tailnet.Workspace
762
+ update * tailnet.WorkspaceUpdate
763
+ expectedDelete * tailnet.WorkspaceUpdate // We only care about deletions added by the function
756
764
}{
757
765
{
758
- name : "NoChange" ,
759
- initialAgents : initialAgents ,
766
+ name : "NoChange" ,
767
+ initialAgents : initialAgents ,
768
+ initialWorkspaces : initialWorkspaces ,
760
769
update : & tailnet.WorkspaceUpdate {
761
770
Kind : tailnet .Snapshot ,
762
771
UpsertedWorkspaces : []* tailnet.Workspace {& ws1 , & ws2 },
@@ -770,8 +779,9 @@ func TestProcessFreshState(t *testing.T) {
770
779
},
771
780
},
772
781
{
773
- name : "AgentAdded" , // Agent 3 added in update
774
- initialAgents : initialAgents ,
782
+ name : "AgentAdded" , // Agent 3 added in update
783
+ initialAgents : initialAgents ,
784
+ initialWorkspaces : initialWorkspaces ,
775
785
update : & tailnet.WorkspaceUpdate {
776
786
Kind : tailnet .Snapshot ,
777
787
UpsertedWorkspaces : []* tailnet.Workspace {& ws1 , & ws2 , & ws3 },
@@ -785,8 +795,9 @@ func TestProcessFreshState(t *testing.T) {
785
795
},
786
796
},
787
797
{
788
- name : "AgentRemovedWorkspaceAlsoRemoved" , // Agent 2 removed, ws2 also removed
789
- initialAgents : initialAgents ,
798
+ name : "AgentRemovedWorkspaceAlsoRemoved" , // Agent 2 removed, ws2 also removed
799
+ initialAgents : initialAgents ,
800
+ initialWorkspaces : initialWorkspaces ,
790
801
update : & tailnet.WorkspaceUpdate {
791
802
Kind : tailnet .Snapshot ,
792
803
UpsertedWorkspaces : []* tailnet.Workspace {& ws1 }, // ws2 not present
@@ -795,15 +806,18 @@ func TestProcessFreshState(t *testing.T) {
795
806
DeletedAgents : []* tailnet.Agent {},
796
807
},
797
808
expectedDelete : & tailnet.WorkspaceUpdate {
798
- DeletedWorkspaces : []* tailnet.Workspace {{ID : wsID2 }}, // Expect ws2 to be deleted
809
+ DeletedWorkspaces : []* tailnet.Workspace {
810
+ {ID : wsID2 , Name : "ws2" , Status : proto .Workspace_RUNNING },
811
+ }, // Expect ws2 to be deleted
799
812
DeletedAgents : []* tailnet.Agent { // Expect agent2 to be deleted
800
813
{ID : agentID2 , Name : "agent2" , WorkspaceID : wsID2 },
801
814
},
802
815
},
803
816
},
804
817
{
805
- name : "AgentRemovedWorkspaceStays" , // Agent 4 removed, but ws1 stays (due to agent1)
806
- initialAgents : initialAgents ,
818
+ name : "AgentRemovedWorkspaceStays" , // Agent 4 removed, but ws1 stays (due to agent1)
819
+ initialAgents : initialAgents ,
820
+ initialWorkspaces : initialWorkspaces ,
807
821
update : & tailnet.WorkspaceUpdate {
808
822
Kind : tailnet .Snapshot ,
809
823
UpsertedWorkspaces : []* tailnet.Workspace {& ws1 , & ws2 }, // ws1 still present
@@ -819,8 +833,9 @@ func TestProcessFreshState(t *testing.T) {
819
833
},
820
834
},
821
835
{
822
- name : "InitialAgentsEmpty" ,
823
- initialAgents : map [uuid.UUID ]tailnet.Agent {}, // Start with no agents known
836
+ name : "InitialAgentsEmpty" ,
837
+ initialAgents : map [uuid.UUID ]tailnet.Agent {}, // Start with no agents known
838
+ initialWorkspaces : map [uuid.UUID ]tailnet.Workspace {},
824
839
update : & tailnet.WorkspaceUpdate {
825
840
Kind : tailnet .Snapshot ,
826
841
UpsertedWorkspaces : []* tailnet.Workspace {& ws1 , & ws2 },
@@ -834,8 +849,9 @@ func TestProcessFreshState(t *testing.T) {
834
849
},
835
850
},
836
851
{
837
- name : "UpdateEmpty" , // Fresh state says nothing exists
838
- initialAgents : initialAgents ,
852
+ name : "UpdateEmpty" , // Snapshot says nothing exists
853
+ initialAgents : initialAgents ,
854
+ initialWorkspaces : initialWorkspaces ,
839
855
update : & tailnet.WorkspaceUpdate {
840
856
Kind : tailnet .Snapshot ,
841
857
UpsertedWorkspaces : []* tailnet.Workspace {},
@@ -844,14 +860,35 @@ func TestProcessFreshState(t *testing.T) {
844
860
DeletedAgents : []* tailnet.Agent {},
845
861
},
846
862
expectedDelete : & tailnet.WorkspaceUpdate { // Expect all initial agents/workspaces to be deleted
847
- DeletedWorkspaces : []* tailnet.Workspace {{ID : wsID1 }, {ID : wsID2 }}, // ws1 and ws2 deleted
863
+ DeletedWorkspaces : []* tailnet.Workspace {
864
+ {ID : wsID1 , Name : "ws1" , Status : proto .Workspace_RUNNING },
865
+ {ID : wsID2 , Name : "ws2" , Status : proto .Workspace_RUNNING },
866
+ }, // ws1 and ws2 deleted
848
867
DeletedAgents : []* tailnet.Agent { // agent1, agent2, agent4 deleted
849
868
{ID : agentID1 , Name : "agent1" , WorkspaceID : wsID1 },
850
869
{ID : agentID2 , Name : "agent2" , WorkspaceID : wsID2 },
851
870
{ID : agentID4 , Name : "agent4" , WorkspaceID : wsID1 },
852
871
},
853
872
},
854
873
},
874
+ {
875
+ name : "WorkspaceWithNoAgents" , // Snapshot says nothing exists
876
+ initialAgents : initialAgents ,
877
+ initialWorkspaces : map [uuid.UUID ]tailnet.Workspace {wsID1 : ws1 , wsID2 : ws2 , wsID4 : ws4 }, // ws4 has no agents
878
+ update : & tailnet.WorkspaceUpdate {
879
+ Kind : tailnet .Snapshot ,
880
+ UpsertedWorkspaces : []* tailnet.Workspace {& ws1 , & ws2 },
881
+ UpsertedAgents : []* tailnet.Agent {& agent1 , & agent2 , & agent4 },
882
+ DeletedWorkspaces : []* tailnet.Workspace {},
883
+ DeletedAgents : []* tailnet.Agent {},
884
+ },
885
+ expectedDelete : & tailnet.WorkspaceUpdate { // Expect all initial agents/workspaces to be deleted
886
+ DeletedWorkspaces : []* tailnet.Workspace {
887
+ {ID : wsID4 , Name : "ws4" , Status : proto .Workspace_RUNNING },
888
+ }, // ws4 should be deleted
889
+ DeletedAgents : []* tailnet.Agent {},
890
+ },
891
+ },
855
892
}
856
893
857
894
for _ , tt := range tests {
@@ -862,7 +899,10 @@ func TestProcessFreshState(t *testing.T) {
862
899
agentsCopy := make (map [uuid.UUID ]tailnet.Agent )
863
900
maps .Copy (agentsCopy , tt .initialAgents )
864
901
865
- processSnapshotUpdate (tt .update , agentsCopy )
902
+ workspaceCopy := make (map [uuid.UUID ]tailnet.Workspace )
903
+ maps .Copy (workspaceCopy , tt .initialWorkspaces )
904
+
905
+ processSnapshotUpdate (tt .update , agentsCopy , workspaceCopy )
866
906
867
907
require .ElementsMatch (t , tt .expectedDelete .DeletedAgents , tt .update .DeletedAgents , "DeletedAgents mismatch" )
868
908
require .ElementsMatch (t , tt .expectedDelete .DeletedWorkspaces , tt .update .DeletedWorkspaces , "DeletedWorkspaces mismatch" )
0 commit comments