add stats list unit tests
@@ -3,6 +3,7 @@ package server_test
import (
"context"
+ "github.com/cri-o/cri-o/internal/oci"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
@@ -31,3 +32,63 @@ var _ = t.Describe("ContainerStats", func() {
})
})
})
+
+var _ = t.Describe("ContainerStatsList", func() {
+ // Prepare the sut
+ BeforeEach(func() {
+ beforeEach()
+ setupSUT()
+ })
+
+ AfterEach(afterEach)
+
+ t.Describe("ContainerStatsList", func() {
+ It("should succeed", func() {
+ // Given
+ addContainerAndSandbox()
+ // When
+ response, err := sut.ListContainerStats(context.Background(),
+ &pb.ListContainerStatsRequest{})
+
+ // Then
+ Expect(err).To(BeNil())
+ Expect(response).NotTo(BeNil())
+ Expect(len(response.Stats)).To(Equal(1))
+ })
+ It("should filter stopped container", func() {
+ // Given
+ state := oci.ContainerState{}
+ state.Status = oci.ContainerStateStopped
+ testContainer.SetState(&state)
+ addContainerAndSandbox()
+
+ // When
+ response, err := sut.ListContainerStats(context.Background(),
+ &pb.ListContainerStatsRequest{},
+ )
+
+ // Then
+ Expect(err).To(BeNil())
+ Expect(response).NotTo(BeNil())
+ Expect(len(response.Stats)).To(Equal(0))
+ })
+ It("should filter by id", func() {
+ // Given
+ addContainerAndSandbox()
+
+ // When
+ response, err := sut.ListContainerStats(context.Background(),
+ &pb.ListContainerStatsRequest{
+ Filter: &pb.ContainerStatsFilter{
+ Id: "invalid",
+ },
+ },
+ )
+
+ // Then
+ Expect(err).To(BeNil())
+ Expect(response).NotTo(BeNil())
+ Expect(len(response.Stats)).To(Equal(0))
+ })
+ })
+})
