Skip to content

Commit

Permalink
Merge branch 'multi-driver-capacity-tracking' of https://github.com/d…
Browse files Browse the repository at this point in the history
…ell/cert-csi into multi-driver-capacity-tracking
  • Loading branch information
niranjan-n1 committed Nov 18, 2024
2 parents a1da721 + 55b9a74 commit 936fcc3
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/k8sclient/resources/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,54 @@ func (suite *PodTestSuite) TestCreatePod() {
}
}

func (suite *PodTestSuite) TestDelete() {
podconf := &pod.Config{
NamePrefix: "pod-prov-test-",
PvcNames: []string{"pvc1", "pvc2", "pvc3"},
VolumeName: "vol",
MountPath: "/data",
ContainerName: "prov-test",
ContainerImage: "quay.io/centos/centos:latest",
Command: []string{"/app/run.sh"},
}

client, err := suite.kubeClient.CreatePodClient("test-namespace")
suite.NoError(err)

podTmpl := client.MakePod(podconf)
suite.Equal("test-namespace", podTmpl.Namespace)

suite.Run("Delete pod test", func() {
result := client.Delete(context.Background(), podTmpl)

suite.NoError(result.GetError())
})
}

func (suite *PodTestSuite) TestDeleteAll() {
podconf := &pod.Config{
NamePrefix: "pod-prov-test-",
PvcNames: []string{"pvc1", "pvc2", "pvc3"},
VolumeName: "vol",
MountPath: "/data",
ContainerName: "prov-test",
ContainerImage: "quay.io/centos/centos:latest",
Command: []string{"/app/run.sh"},
}

client, err := suite.kubeClient.CreatePodClient("test-namespace")
suite.NoError(err)

podTmpl := client.MakePod(podconf)
suite.Equal("test-namespace", podTmpl.Namespace)

suite.Run("Delete all pod test", func() {
err := client.DeleteAll(context.Background())

suite.NoError(err)
})
}

func TestPodTestSuite(t *testing.T) {
suite.Run(t, new(PodTestSuite))
}
134 changes: 134 additions & 0 deletions pkg/testcore/suites/functional-suites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
* limitations under the License.
*
*/

package suites

import (
"errors"
"reflect"
"testing"

"github.com/dell/cert-csi/pkg/observer"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -49,3 +52,134 @@ func TestGetTopologyCount(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, 0, topologyCount)
}

func TestVolumeDeletionSuite_GetName(t *testing.T) {
tests := []struct {
name string
vds *VolumeDeletionSuite
want string
}{
{
name: "Testing GetName when Description is not empty",
vds: &VolumeDeletionSuite{
DeletionStruct: &DeletionStruct{
Name: "test-volume",
Namespace: "test-namespace",
Description: "test-description",
},
},
want: "test-description",
},
{
name: "Testing GetName when Description is empty",
vds: &VolumeDeletionSuite{
DeletionStruct: &DeletionStruct{
Name: "test-volume",
Namespace: "test-namespace",
},
},
want: "VolumeDeletionSuite",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.vds.GetName(); got != tt.want {
t.Errorf("VolumeDeletionSuite.GetName() = %v, want %v", got, tt.want)
}
})
}
}

func TestVolumeDeletionSuite_GetObservers(t *testing.T) {
type args struct {
obsType observer.Type
}
tests := []struct {
name string
v *VolumeDeletionSuite
args args
want []observer.Interface
}{
{
name: "Testing GetObservers with event type",
v: &VolumeDeletionSuite{},
args: args{
obsType: observer.EVENT,
},
want: []observer.Interface{
&observer.PvcObserver{},
&observer.EntityNumberObserver{},
&observer.ContainerMetricsObserver{},
},
},
{
name: "Testing GetObservers with list type",
v: &VolumeDeletionSuite{},
args: args{
obsType: observer.LIST,
},
want: []observer.Interface{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.v.GetObservers(tt.args.obsType); !reflect.DeepEqual(got, tt.want) {
t.Errorf("VolumeDeletionSuite.GetObservers() = %v, want %v", got, tt.want)
}
})
}
}
func TestVolumeDeletionSuite_GetNamespace(t *testing.T) {
tests := []struct {
name string
vds *VolumeDeletionSuite
want string
}{
{
name: "Testing GetNamespace when Namespace is not empty",
vds: &VolumeDeletionSuite{
DeletionStruct: &DeletionStruct{
Namespace: "test-namespace",
},
},
want: "test-namespace",
},
{
name: "Testing GetNamespace when Namespace is empty",
vds: &VolumeDeletionSuite{
DeletionStruct: &DeletionStruct{
Namespace: "",
},
},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.vds.GetNamespace(); got != tt.want {
t.Errorf("VolumeDeletionSuite.GetNamespace() = %v, want %v", got, tt.want)
}
})
}
}

func TestVolumeDeletionSuite_Parameters(t *testing.T) {
tests := []struct {
name string
vds *VolumeDeletionSuite
want string
}{
{
name: "Testing Parameters",
vds: &VolumeDeletionSuite{},
want: "{}",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.vds.Parameters(); got != tt.want {
t.Errorf("VolumeDeletionSuite.Parameters() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 936fcc3

Please sign in to comment.