Skip to content

Commit

Permalink
Add ut
Browse files Browse the repository at this point in the history
Signed-off-by: Zhonghu Xu <xuzhonghu@huawei.com>
  • Loading branch information
hzxuzhonghu committed Aug 19, 2024
1 parent f121f6d commit c9a3eab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/controller/workload/workload_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (p *Processor) handleWorkload(workload *workloadapi.Workload) error {

deletedServices, newServices = p.WorkloadCache.AddOrUpdateWorkload(workload)

// Exlude the unhealthy workload, which means the workload is not ready
// Exclude the unhealthy workload, which means the workload is not ready
if workload.Status == workloadapi.WorkloadStatus_UNHEALTHY {
return nil
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/workload/workload_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ func Test_handleWorkload(t *testing.T) {
// 6.2 check service map contains service, but no waypoint address
checkServiceMap(t, p, svcID, wpSvc, 0)

// 5. add unhealthy workload
workload3 := createFakeWorkload("1.2.3.6")

Check failure on line 152 in pkg/controller/workload/workload_processor_test.go

View workflow job for this annotation

GitHub Actions / build (1.22)

not enough arguments in call to createFakeWorkload
workload3.Status = workloadapi.WorkloadStatus_UNHEALTHY
_ = p.handleWorkload(workload3)

addr, _ := netip.AddrFromSlice(workload3.Addresses[0])
networkAddress := cache.NetworkAddress{
Network: workload3.Network,
Address: addr,
}
got := p.WorkloadCache.GetWorkloadByAddr(networkAddress)
assert.NotNil(t, got)
assert.Equal(t, got.Status, workloadapi.WorkloadStatus_UNHEALTHY)

// 5.1 check unhealthy workload does not exists
var fk bpfcache.FrontendKey
var fv bpfcache.FrontendValue
nets.CopyIpByteFromSlice(&fk.Ip, workload3.Addresses[0])
err = p.bpf.FrontendLookup(&fk, &fv)
assert.ErrorContains(t, err, "key does not exist")

hashNameClean(p)
}

Expand Down

0 comments on commit c9a3eab

Please sign in to comment.