Skip to content

Commit 687b261

Browse files
test: add unit test for ServiceBatchUpdate
Signed-off-by: Shivansh Sahu <sahushivansh142@gmail.com>
1 parent 59b0b2b commit 687b261

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright The Kmesh Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bpfcache
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestServiceBatchUpdate(t *testing.T) {
26+
// 1. Setup Fake BPF Map (Same helper as in endpoint_test.go)
27+
workloadMap := NewFakeWorkloadMap(t)
28+
defer CleanupFakeWorkloadMap(workloadMap)
29+
30+
c := NewCache(workloadMap)
31+
32+
// 2. Prepare Batch Data
33+
keys := []ServiceKey{
34+
{ServiceId: 100},
35+
{ServiceId: 200},
36+
}
37+
values := []ServiceValue{
38+
{LbPolicy: 1}, // Random
39+
{LbPolicy: 1},
40+
}
41+
42+
// 3. Call the function we need to cover
43+
count, err := c.ServiceBatchUpdate(keys, values)
44+
45+
// 4. Assertions
46+
assert.Nil(t, err)
47+
assert.Equal(t, 2, count)
48+
49+
// 5. Verify data was actually written to the map
50+
var lookupVal ServiceValue
51+
err = c.ServiceLookup(&keys[0], &lookupVal)
52+
assert.Nil(t, err)
53+
assert.Equal(t, values[0].LbPolicy, lookupVal.LbPolicy)
54+
}

0 commit comments

Comments
 (0)