FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
stackrox/pkg/maputil/maputil_test.go at master · stackrox/stackrox · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
stackrox
/
stackrox
Public
Notifications
You must be signed in to change notification settings
Fork
191
Star
1.3k
Code
Issues
54
Pull requests
604
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
stackrox
/
pkg
/
maputil
/
maputil_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
90 lines (74 loc) · 1.67 KB
Breadcrumbs
stackrox
/
pkg
/
maputil
/
maputil_test.go
Copy path
File metadata and controls
90 lines (74 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package
maputil
import
(
"strconv"
"testing"
"github.com/stackrox/rox/pkg/buildinfo"
"github.com/stackrox/rox/pkg/sync"
"github.com/stretchr/testify/assert"
)
func
TestShallowClone
(
t
*
testing.
T
) {
a
:=
assert
.
New
(
t
)
m
:=
map
[
string
]
string
{
"a"
:
"1"
,
"b"
:
"2"
,
}
cloned
:=
ShallowClone
(
m
)
cloned
[
"c"
]
=
"3"
delete
(
cloned
,
"a"
)
a
.
Equal
(
map
[
string
]
string
{
"a"
:
"1"
,
"b"
:
"2"
,
},
m
)
a
.
Equal
(
map
[
string
]
string
{
"b"
:
"2"
,
"c"
:
"3"
,
},
cloned
)
}
func
TestFastRMap
(
t
*
testing.
T
) {
a
:=
assert
.
New
(
t
)
m
:=
NewFastRMap
[
string
,
string
]()
m
.
Set
(
"a"
,
"1"
)
a
.
Equal
(
map
[
string
]
string
{
"a"
:
"1"
},
m
.
GetMap
())
got
,
exists
:=
m
.
Get
(
"a"
)
a
.
True
(
exists
)
a
.
Equal
(
got
,
"1"
)
got
,
exists
=
m
.
Get
(
"b"
)
a
.
False
(
exists
)
a
.
Equal
(
got
,
""
)
m
.
Delete
(
"a"
)
a
.
Equal
(
map
[
string
]
string
{},
m
.
GetMap
())
}
func
TestFastRMapThreadSafe
(
t
*
testing.
T
) {
a
:=
assert
.
New
(
t
)
var
wg
sync.
WaitGroup
m
:=
NewFastRMap
[
string
,
string
]()
numThreads
:=
1000
if
buildinfo
.
RaceEnabled
{
numThreads
=
100
// race detector chokes on this if we have too many goroutines
}
for
i
:=
0
;
i
<
numThreads
;
i
++
{
wg
.
Add
(
1
)
go
func
(
index
int
) {
defer
wg
.
Done
()
m
.
Set
(
"a"
,
"1"
)
m
.
Set
(
strconv
.
Itoa
(
index
),
"2"
)
_
=
m
.
GetMap
()
m
.
Delete
(
"a"
)
got
,
exists
:=
m
.
Get
(
strconv
.
Itoa
(
index
))
a
.
True
(
exists
)
a
.
Equal
(
got
,
"2"
)
}(
i
)
}
wg
.
Wait
()
currentMap
:=
m
.
GetMap
()
a
.
Len
(
currentMap
,
numThreads
)
expectedKeys
:=
make
([]
string
,
0
,
numThreads
)
for
i
:=
0
;
i
<
numThreads
;
i
++
{
expectedKeys
=
append
(
expectedKeys
,
strconv
.
Itoa
(
i
))
}
mapKeys
:=
make
([]
string
,
0
,
numThreads
)
for
k
:=
range
currentMap
{
mapKeys
=
append
(
mapKeys
,
k
)
}
assert
.
ElementsMatch
(
t
,
mapKeys
,
expectedKeys
)
}
Back
|
FazBrowse Home
|
New Git URL