mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-17 15:38:00 +00:00
test: add test for network metric
add test for metric interface Signed-off-by: Ace-Tang <aceapril@126.com>
This commit is contained in:
parent
dc38ba77bd
commit
4a28b52553
56
containerd-shim-v2/metrics_test.go
Normal file
56
containerd-shim-v2/metrics_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (c) 2017 Intel Corporation
|
||||||
|
// Copyright (c) 2018 HyperHQ Inc.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package containerdshim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/containerd/cgroups"
|
||||||
|
"github.com/containerd/containerd/namespaces"
|
||||||
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStatNetworkMetric(t *testing.T) {
|
||||||
|
|
||||||
|
assert := assert.New(t)
|
||||||
|
var err error
|
||||||
|
|
||||||
|
mockNetwork := []*vc.NetworkStats{
|
||||||
|
{
|
||||||
|
Name: "test-network",
|
||||||
|
RxBytes: 10,
|
||||||
|
TxBytes: 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedNetwork := []*cgroups.NetworkStat{
|
||||||
|
{
|
||||||
|
Name: "test-network",
|
||||||
|
RxBytes: 10,
|
||||||
|
TxBytes: 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
testingImpl.StatsContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||||
|
return vc.ContainerStats{
|
||||||
|
NetworkStats: mockNetwork,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
testingImpl.StatsContainerFunc = nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
ctx := namespaces.WithNamespace(context.Background(), "UnitTest")
|
||||||
|
resp, err := testingImpl.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
metrics := statsToMetrics(&resp)
|
||||||
|
assert.Equal(expectedNetwork, metrics.Network)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user