(t *testing.T)
| 983 | } |
| 984 | |
| 985 | func TestProcessFreshState(t *testing.T) { |
| 986 | t.Parallel() |
| 987 | |
| 988 | wsID1 := uuid.New() |
| 989 | wsID2 := uuid.New() |
| 990 | wsID3 := uuid.New() |
| 991 | wsID4 := uuid.New() |
| 992 | |
| 993 | agentID1 := uuid.New() |
| 994 | agentID2 := uuid.New() |
| 995 | agentID3 := uuid.New() |
| 996 | agentID4 := uuid.New() |
| 997 | |
| 998 | agent1 := tailnet.Agent{ID: agentID1, Name: "agent1", WorkspaceID: wsID1} |
| 999 | agent2 := tailnet.Agent{ID: agentID2, Name: "agent2", WorkspaceID: wsID2} |
| 1000 | agent3 := tailnet.Agent{ID: agentID3, Name: "agent3", WorkspaceID: wsID3} |
| 1001 | agent4 := tailnet.Agent{ID: agentID4, Name: "agent4", WorkspaceID: wsID1} |
| 1002 | |
| 1003 | ws1 := tailnet.Workspace{ID: wsID1, Name: "ws1", Status: proto.Workspace_RUNNING} |
| 1004 | ws2 := tailnet.Workspace{ID: wsID2, Name: "ws2", Status: proto.Workspace_RUNNING} |
| 1005 | ws3 := tailnet.Workspace{ID: wsID3, Name: "ws3", Status: proto.Workspace_RUNNING} |
| 1006 | ws4 := tailnet.Workspace{ID: wsID4, Name: "ws4", Status: proto.Workspace_RUNNING} |
| 1007 | |
| 1008 | initialAgents := map[uuid.UUID]tailnet.Agent{ |
| 1009 | agentID1: agent1, |
| 1010 | agentID2: agent2, |
| 1011 | agentID4: agent4, |
| 1012 | } |
| 1013 | initialWorkspaces := map[uuid.UUID]tailnet.Workspace{ |
| 1014 | wsID1: ws1, |
| 1015 | wsID2: ws2, |
| 1016 | } |
| 1017 | |
| 1018 | tests := []struct { |
| 1019 | name string |
| 1020 | initialAgents map[uuid.UUID]tailnet.Agent |
| 1021 | initialWorkspaces map[uuid.UUID]tailnet.Workspace |
| 1022 | update *tailnet.WorkspaceUpdate |
| 1023 | expectedDelete *tailnet.WorkspaceUpdate // We only care about deletions added by the function |
| 1024 | }{ |
| 1025 | { |
| 1026 | name: "NoChange", |
| 1027 | initialAgents: initialAgents, |
| 1028 | initialWorkspaces: initialWorkspaces, |
| 1029 | update: &tailnet.WorkspaceUpdate{ |
| 1030 | Kind: tailnet.Snapshot, |
| 1031 | UpsertedWorkspaces: []*tailnet.Workspace{&ws1, &ws2}, |
| 1032 | UpsertedAgents: []*tailnet.Agent{&agent1, &agent2, &agent4}, |
| 1033 | DeletedWorkspaces: []*tailnet.Workspace{}, |
| 1034 | DeletedAgents: []*tailnet.Agent{}, |
| 1035 | }, |
| 1036 | expectedDelete: &tailnet.WorkspaceUpdate{ // Expect no *additional* deletions |
| 1037 | DeletedWorkspaces: []*tailnet.Workspace{}, |
| 1038 | DeletedAgents: []*tailnet.Agent{}, |
| 1039 | }, |
| 1040 | }, |
| 1041 | { |
| 1042 | name: "AgentAdded", // Agent 3 added in update |
nothing calls this directly
no test coverage detected