Skip to content

Commit ca2e1bf

Browse files
committed
removed unecessary test for verifying existing deletetions (fresh state never has them)
1 parent 3d39713 commit ca2e1bf

File tree

1 file changed

+7
-53
lines changed

1 file changed

+7
-53
lines changed

vpn/tunnel_internal_test.go

+7-53
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net/netip"
88
"net/url"
99
"slices"
10-
"sort"
1110
"strings"
1211
"sync"
1312
"testing"
@@ -731,12 +730,12 @@ func TestProcessFreshState(t *testing.T) {
731730
agentID1 := uuid.New()
732731
agentID2 := uuid.New()
733732
agentID3 := uuid.New()
734-
agentID4 := uuid.New() // Belongs to wsID1
733+
agentID4 := uuid.New()
735734

736735
agent1 := tailnet.Agent{ID: agentID1, Name: "agent1", WorkspaceID: wsID1}
737736
agent2 := tailnet.Agent{ID: agentID2, Name: "agent2", WorkspaceID: wsID2}
738737
agent3 := tailnet.Agent{ID: agentID3, Name: "agent3", WorkspaceID: wsID3}
739-
agent4 := tailnet.Agent{ID: agentID4, Name: "agent4", WorkspaceID: wsID1} // Same workspace as agent1
738+
agent4 := tailnet.Agent{ID: agentID4, Name: "agent4", WorkspaceID: wsID1}
740739

741740
ws1 := tailnet.Workspace{ID: wsID1, Name: "ws1"}
742741
ws2 := tailnet.Workspace{ID: wsID2, Name: "ws2"}
@@ -745,7 +744,7 @@ func TestProcessFreshState(t *testing.T) {
745744
initialAgents := map[uuid.UUID]tailnet.Agent{
746745
agentID1: agent1,
747746
agentID2: agent2,
748-
agentID4: agent4, // agent 4 is initially present
747+
agentID4: agent4,
749748
}
750749

751750
tests := []struct {
@@ -761,8 +760,8 @@ func TestProcessFreshState(t *testing.T) {
761760
FreshState: true,
762761
UpsertedWorkspaces: []*tailnet.Workspace{&ws1, &ws2},
763762
UpsertedAgents: []*tailnet.Agent{&agent1, &agent2, &agent4},
764-
DeletedWorkspaces: []*tailnet.Workspace{}, // Input deletions
765-
DeletedAgents: []*tailnet.Agent{}, // Input deletions
763+
DeletedWorkspaces: []*tailnet.Workspace{},
764+
DeletedAgents: []*tailnet.Agent{},
766765
},
767766
expectedDelete: &tailnet.WorkspaceUpdate{ // Expect no *additional* deletions
768767
DeletedWorkspaces: []*tailnet.Workspace{},
@@ -852,65 +851,20 @@ func TestProcessFreshState(t *testing.T) {
852851
},
853852
},
854853
},
855-
{
856-
name: "UpdateWithExistingDeletions", // Agent 2 removed, ws2 also removed, but update already contains some deletions
857-
initialAgents: initialAgents,
858-
update: &tailnet.WorkspaceUpdate{
859-
FreshState: true,
860-
UpsertedWorkspaces: []*tailnet.Workspace{&ws1}, // ws2 not present
861-
UpsertedAgents: []*tailnet.Agent{&agent1, &agent4}, // agent2 not present
862-
DeletedWorkspaces: []*tailnet.Workspace{{ID: uuid.New()}}, // Pre-existing deletion
863-
DeletedAgents: []*tailnet.Agent{{ID: uuid.New()}}, // Pre-existing deletion
864-
},
865-
expectedDelete: &tailnet.WorkspaceUpdate{
866-
DeletedWorkspaces: []*tailnet.Workspace{{ID: wsID2}}, // Expect ws2 to be added to deletions
867-
DeletedAgents: []*tailnet.Agent{ // Expect agent2 to be added to deletions
868-
{ID: agentID2, Name: "agent2", WorkspaceID: wsID2},
869-
},
870-
},
871-
},
872854
}
873855

874856
for _, tt := range tests {
875857
tt := tt
876858
t.Run(tt.name, func(t *testing.T) {
877859
t.Parallel()
878860

879-
// Keep track of original lengths to compare only the added elements
880-
originalDeletedAgentsLen := len(tt.update.DeletedAgents)
881-
originalDeletedWorkspacesLen := len(tt.update.DeletedWorkspaces)
882-
883861
agentsCopy := make(map[uuid.UUID]tailnet.Agent)
884862
maps.Copy(agentsCopy, tt.initialAgents)
885863

886864
processFreshState(tt.update, agentsCopy)
887865

888-
// Extract only the elements added by processFreshState
889-
addedDeletedAgents := tt.update.DeletedAgents[originalDeletedAgentsLen:]
890-
addedDeletedWorkspaces := tt.update.DeletedWorkspaces[originalDeletedWorkspacesLen:]
891-
892-
// Sort slices for consistent comparison
893-
sortAgents(addedDeletedAgents)
894-
sortAgents(tt.expectedDelete.DeletedAgents)
895-
sortWorkspaces(addedDeletedWorkspaces)
896-
sortWorkspaces(tt.expectedDelete.DeletedWorkspaces)
897-
898-
require.ElementsMatch(t, tt.expectedDelete.DeletedAgents, addedDeletedAgents, "DeletedAgents mismatch")
899-
require.ElementsMatch(t, tt.expectedDelete.DeletedWorkspaces, addedDeletedWorkspaces, "DeletedWorkspaces mismatch")
866+
require.ElementsMatch(t, tt.expectedDelete.DeletedAgents, tt.update.DeletedAgents, "DeletedAgents mismatch")
867+
require.ElementsMatch(t, tt.expectedDelete.DeletedWorkspaces, tt.update.DeletedWorkspaces, "DeletedWorkspaces mismatch")
900868
})
901869
}
902870
}
903-
904-
// sortAgents sorts a slice of Agents by ID for consistent comparison.
905-
func sortAgents(agents []*tailnet.Agent) {
906-
sort.Slice(agents, func(i, j int) bool {
907-
return agents[i].ID.String() < agents[j].ID.String()
908-
})
909-
}
910-
911-
// sortWorkspaces sorts a slice of Workspaces by ID for consistent comparison.
912-
func sortWorkspaces(workspaces []*tailnet.Workspace) {
913-
sort.Slice(workspaces, func(i, j int) bool {
914-
return workspaces[i].ID.String() < workspaces[j].ID.String()
915-
})
916-
}

0 commit comments

Comments
 (0)