MCPcopy
hub / github.com/safing/portmaster / createRandomTestMap

Function createRandomTestMap

spn/navigator/map_test.go:48–155  ·  view source on GitHub ↗
(seed int64, size int)

Source from the content-addressed store, hash-verified

46}
47
48func createRandomTestMap(seed int64, size int) *Map {
49 fakeLock.Lock()
50 defer fakeLock.Unlock()
51
52 // Seed with parameter to make it reproducible.
53 gofakeit.Seed(seed)
54
55 // Enforce minimum size.
56 if size < 10 {
57 size = 10
58 }
59
60 // Create Hub list.
61 hubs := make([]*hub.Hub, 0, size)
62
63 // Create Intel data structure.
64 mapIntel := &hub.Intel{
65 Hubs: make(map[string]*hub.HubIntel),
66 }
67
68 // Define periodic values.
69 var currentGroup string
70
71 // Create [size] fake Hubs.
72 for i := range size {
73 // Change group every 5 Hubs.
74 if i%5 == 0 {
75 currentGroup = gofakeit.Username()
76 }
77
78 // Create new fake Hub and add to the list.
79 h := createFakeHub(currentGroup, true, mapIntel)
80 hubs = append(hubs, h)
81 }
82
83 // Fake three superseeded Hubs.
84 for i := range 3 {
85 h := hubs[size-1-i]
86
87 // Set FirstSeen in the past and copy an IP address of an existing Hub.
88 h.FirstSeen = time.Now().Add(-1 * time.Hour)
89 if i%2 == 0 {
90 h.Info.IPv4 = hubs[i].Info.IPv4
91 } else {
92 h.Info.IPv6 = hubs[i].Info.IPv6
93 }
94 }
95
96 // Create Lanes between Hubs in order to create the network.
97 totalConnections := size * 10
98 for range totalConnections {
99 // Get new random indexes.
100 indexA := gofakeit.Number(0, size-1)
101 indexB := gofakeit.Number(0, size-1)
102 if indexA == indexB {
103 continue
104 }
105

Callers 2

getDefaultTestMapFunction · 0.85

Calls 13

ParseAdvisoriesMethod · 0.95
UpdateHubMethod · 0.95
createFakeHubFunction · 0.85
createLaneFunction · 0.85
NewMapFunction · 0.85
findFakeHomeHubFunction · 0.85
GetLaneToMethod · 0.80
AddLaneMethod · 0.80
MarkAsFailingForMethod · 0.80
addStatesMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected