summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKubeEdge Bot <48982446+kubeedge-bot@users.noreply.github.com>2024-08-08 21:51:20 +0800
committerGitHub <noreply@github.com>2024-08-08 21:51:20 +0800
commit31436aa60c1816999826976d8c727600ff2bf17d (patch)
tree1c2032744dc4af3df273f21de366973361bc1bb7
parentMerge pull request #5778 from 1Shubham7/metaserver (diff)
parentTests for storage/v1 module (diff)
downloadkubeedge-31436aa60c1816999826976d8c727600ff2bf17d.tar.gz
Merge pull request #5763 from 1Shubham7/ut
Tests for `storage/v1` module
-rw-r--r--edge/pkg/edged/kubeclientbridge/typed/storage/v1/storage_client_bridge_test.go46
-rw-r--r--edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go104
2 files changed, 150 insertions, 0 deletions
diff --git a/edge/pkg/edged/kubeclientbridge/typed/storage/v1/storage_client_bridge_test.go b/edge/pkg/edged/kubeclientbridge/typed/storage/v1/storage_client_bridge_test.go
new file mode 100644
index 000000000..24fca502a
--- /dev/null
+++ b/edge/pkg/edged/kubeclientbridge/typed/storage/v1/storage_client_bridge_test.go
@@ -0,0 +1,46 @@
+/*
+Copyright 2024 The KubeEdge Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package v1
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ fakestoragev1 "k8s.io/client-go/kubernetes/typed/storage/v1/fake"
+
+ "github.com/kubeedge/kubeedge/edge/pkg/metamanager/client"
+)
+
+func TestVolumeAttachments(t *testing.T) {
+ assert := assert.New(t)
+
+ metaClient := client.New()
+ bridge := &StorageV1Bridge{
+ FakeStorageV1: fakestoragev1.FakeStorageV1{},
+ MetaClient: metaClient,
+ }
+
+ volumeAttachments := bridge.VolumeAttachments()
+
+ assert.NotNil(volumeAttachments)
+ assert.IsType(&VolumeAttachmentsBridge{}, volumeAttachments)
+
+ volumeAttachmentsBridge, ok := volumeAttachments.(*VolumeAttachmentsBridge)
+ assert.True(ok)
+ assert.Equal(metaClient, volumeAttachmentsBridge.MetaClient)
+ assert.IsType(fakestoragev1.FakeVolumeAttachments{}, volumeAttachmentsBridge.FakeVolumeAttachments)
+}
diff --git a/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go b/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go
new file mode 100644
index 000000000..15f42de51
--- /dev/null
+++ b/edge/pkg/edged/kubeclientbridge/typed/storage/v1/volumeattachment_bridge_test.go
@@ -0,0 +1,104 @@
+/*
+Copyright 2024 The KubeEdge Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package v1
+
+import (
+ "context"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ storagev1 "k8s.io/api/storage/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ fakestoragev1 "k8s.io/client-go/kubernetes/typed/storage/v1/fake"
+
+ "github.com/kubeedge/kubeedge/edge/pkg/metamanager/client"
+)
+
+type mockVolumeAttachmentsInterface struct {
+ volumeAttachment *storagev1.VolumeAttachment
+ err error
+}
+
+func (f *mockVolumeAttachmentsInterface) Create(*storagev1.VolumeAttachment) (*storagev1.VolumeAttachment, error) {
+ return nil, nil
+}
+
+func (f *mockVolumeAttachmentsInterface) Update(*storagev1.VolumeAttachment) error {
+ return nil
+}
+
+func (f *mockVolumeAttachmentsInterface) Delete(_ string) error {
+ return nil
+}
+
+func (f *mockVolumeAttachmentsInterface) Get(_ string, _ metav1.GetOptions) (*storagev1.VolumeAttachment, error) {
+ return f.volumeAttachment, f.err
+}
+
+type mockMetaClient struct {
+ volumeAttachments client.VolumeAttachmentsInterface
+}
+
+func (f *mockMetaClient) VolumeAttachments(_ string) client.VolumeAttachmentsInterface {
+ return f.volumeAttachments
+}
+
+func (f *mockMetaClient) Pods(string) client.PodsInterface { return nil }
+func (f *mockMetaClient) PodStatus(string) client.PodStatusInterface { return nil }
+func (f *mockMetaClient) ConfigMaps(string) client.ConfigMapsInterface { return nil }
+func (f *mockMetaClient) Nodes(string) client.NodesInterface { return nil }
+func (f *mockMetaClient) NodeStatus(string) client.NodeStatusInterface { return nil }
+func (f *mockMetaClient) Secrets(string) client.SecretsInterface { return nil }
+func (f *mockMetaClient) ServiceAccountToken() client.ServiceAccountTokenInterface { return nil }
+func (f *mockMetaClient) ServiceAccounts(string) client.ServiceAccountInterface { return nil }
+func (f *mockMetaClient) PersistentVolumes(string) client.PersistentVolumesInterface { return nil }
+func (f *mockMetaClient) PersistentVolumeClaims(string) client.PersistentVolumeClaimsInterface {
+ return nil
+}
+func (f *mockMetaClient) Leases(string) client.LeasesInterface { return nil }
+func (f *mockMetaClient) CertificateSigningRequests() client.CertificateSigningRequestInterface {
+ return nil
+}
+
+func TestGet(t *testing.T) {
+ assert := assert.New(t)
+
+ expectedVolumeAttachment := &storagev1.VolumeAttachment{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test-volume-attachment",
+ },
+ }
+
+ mockVolumeAttachments := &mockVolumeAttachmentsInterface{
+ volumeAttachment: expectedVolumeAttachment,
+ err: nil,
+ }
+
+ mockMetaClient := &mockMetaClient{
+ volumeAttachments: mockVolumeAttachments,
+ }
+
+ volumeAttachmentsBridge := &VolumeAttachmentsBridge{
+ FakeVolumeAttachments: fakestoragev1.FakeVolumeAttachments{},
+ MetaClient: mockMetaClient,
+ }
+
+ result, err := volumeAttachmentsBridge.Get(context.Background(), "test-volume-attachment", metav1.GetOptions{})
+
+ assert.NoError(err)
+ assert.Equal(expectedVolumeAttachment, result)
+}