Skip to content

Commit aa753ef

Browse files
committed
feat:add RemoveResourceNodes
1 parent 1c2645a commit aa753ef

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

core/stat/node_storage.go

+11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ func GetResourceNode(resource string) *ResourceNode {
5454
return resNodeMap[resource]
5555
}
5656

57+
func RemoveResourceNodes(resources []string) {
58+
if len(resources) == 0 {
59+
return
60+
}
61+
rnsMux.Lock()
62+
defer rnsMux.Unlock()
63+
for _, resource := range resources {
64+
delete(resNodeMap, resource)
65+
}
66+
}
67+
5768
func GetOrCreateResourceNode(resource string, resourceType base.ResourceType) *ResourceNode {
5869
node := GetResourceNode(resource)
5970
if node != nil {

core/stat/node_storage_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package stat
2+
3+
import "testing"
4+
5+
func TestRemoveResourceNodes(t *testing.T) {
6+
type args struct {
7+
resources []string
8+
}
9+
tests := []struct {
10+
name string
11+
args args
12+
}{
13+
{
14+
name: "empty",
15+
args: args{},
16+
},
17+
{
18+
name: "normal",
19+
args: args{
20+
resources: []string{"test"},
21+
},
22+
},
23+
}
24+
for _, tt := range tests {
25+
t.Run(tt.name, func(t *testing.T) {
26+
RemoveResourceNodes(tt.args.resources)
27+
})
28+
}
29+
}

0 commit comments

Comments
 (0)