Skip to content

Commit

Permalink
Added clientset tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 10, 2024
1 parent e9c7e16 commit 73e4332
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/driver/provisioner_server_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ var FetchSecretInformation = fetchObjectStorageProviderSecretInfo
var FetchParameters = fetchS3Parameters

func InitProvisionerServer(provisioner string) (cosiapi.ProvisionerServer, error) {
klog.V(3).InfoS("Initializing ProvisionerServer", "provisioner", provisioner)
if provisioner == "" {
err := errors.New("provisioner name cannot be empty")
klog.ErrorS(err, "Failed to initialize ProvisionerServer: empty provisioner name")
return nil, err
}
klog.V(3).InfoS("Initializing ProvisionerServer", "provisioner", provisioner)

kubeConfig, err := InClusterConfig()
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions pkg/driver/provisioner_server_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ import (
cosiapi "sigs.k8s.io/container-object-storage-interface-spec"
)

var _ = Describe("ProvisionerServer Global Kubernetes and Bucket Client", func() {
var (
kubeConfig *rest.Config
)

BeforeEach(func() {
// Initialize a mock kubeConfig for tests
kubeConfig = &rest.Config{
Host: "https://mock-server",
}
})

Describe("NewKubernetesClient", func() {
It("should return a Kubernetes client interface when called with a valid config", func() {
client, err := driver.NewKubernetesClient(kubeConfig)
Expect(err).To(BeNil())
Expect(client).NotTo(BeNil())
_, ok := client.(*kubernetes.Clientset)
Expect(ok).To(BeTrue())
})
})

Describe("NewBucketClient", func() {
It("should return a Bucket client interface when called with a valid config", func() {
client, err := driver.NewBucketClient(kubeConfig)
Expect(err).To(BeNil())
Expect(client).NotTo(BeNil())
_, ok := client.(*bucketclientset.Clientset)
Expect(ok).To(BeTrue())
})
})
})

var _ = Describe("ProvisionerServer InitProvisionerServer", func() {
var (
provisioner string
Expand Down

0 comments on commit 73e4332

Please sign in to comment.