Skip to content

Commit

Permalink
Add foundational test code for node agent
Browse files Browse the repository at this point in the history
Signed-off-by: Ameya Gawde <agawde@mirantis.com>
  • Loading branch information
ameyag committed Jul 30, 2020
1 parent fc16340 commit fe83529
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
59 changes: 59 additions & 0 deletions agent/csi/plugin_fakes_test.go
@@ -0,0 +1,59 @@
package csi

import (
"context"
"fmt"

"google.golang.org/grpc"

"github.com/container-storage-interface/spec/lib/go/csi"
)

type fakeNodeClient struct {
// getInfoRequests is a log of all requests to NodeGetInfo.
getInfoRequests []*csi.NodeGetInfoRequest
// idCounter is a simple way to generate ids
idCounter int
}

func newFakeNodeClient() *fakeNodeClient {
return &fakeNodeClient{
getInfoRequests: []*csi.NodeGetInfoRequest{},
}
}

func (f *fakeNodeClient) NodeGetInfo(ctx context.Context, in *csi.NodeGetInfoRequest, _ ...grpc.CallOption) (*csi.NodeGetInfoResponse, error) {
f.idCounter++
f.getInfoRequests = append(f.getInfoRequests, in)
return &csi.NodeGetInfoResponse{
NodeId: fmt.Sprintf("nodeid%d", f.idCounter),
}, nil
}

func (f *fakeNodeClient) NodeStageVolume(ctx context.Context, in *csi.NodeStageVolumeRequest, opts ...grpc.CallOption) (*csi.NodeStageVolumeResponse, error) {
return nil, nil
}

func (f *fakeNodeClient) NodeUnstageVolume(ctx context.Context, in *csi.NodeUnstageVolumeRequest, opts ...grpc.CallOption) (*csi.NodeUnstageVolumeResponse, error) {
return nil, nil
}

func (f *fakeNodeClient) NodePublishVolume(ctx context.Context, in *csi.NodePublishVolumeRequest, opts ...grpc.CallOption) (*csi.NodePublishVolumeResponse, error) {
return nil, nil
}

func (f *fakeNodeClient) NodeUnpublishVolume(ctx context.Context, in *csi.NodeUnpublishVolumeRequest, opts ...grpc.CallOption) (*csi.NodeUnpublishVolumeResponse, error) {
return nil, nil
}

func (f *fakeNodeClient) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVolumeStatsRequest, opts ...grpc.CallOption) (*csi.NodeGetVolumeStatsResponse, error) {
return nil, nil
}

func (f *fakeNodeClient) NodeExpandVolume(ctx context.Context, in *csi.NodeExpandVolumeRequest, opts ...grpc.CallOption) (*csi.NodeExpandVolumeResponse, error) {
return nil, nil
}

func (f *fakeNodeClient) NodeGetCapabilities(ctx context.Context, in *csi.NodeGetCapabilitiesRequest, opts ...grpc.CallOption) (*csi.NodeGetCapabilitiesResponse, error) {
return nil, nil
}
57 changes: 57 additions & 0 deletions agent/csi/plugin_test.go
@@ -0,0 +1,57 @@
package csi

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"context"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/docker/swarmkit/api"
)

const driverName = "testdriver"

// newPluginFromClients creates a new node plugin using the provided CSI RPC
// clients.
func newPluginFromClients(name string, nodeClient csi.NodeClient, nodeId string) *NodePlugin {
return &NodePlugin{
Name: name,
NodeClient: nodeClient,
NodeID: nodeId,
}
}

var _ = Describe("Plugin Node", func() {
var (
nodePlugin *NodePlugin

nodeClient *fakeNodeClient

nodeInfo *api.NodeCSIInfo

err error
)

BeforeEach(func() {

nodeClient = newFakeNodeClient()

nodePlugin = newPluginFromClients(driverName, nodeClient, "1")
})

JustBeforeEach(func() {
nodeInfo, err = nodePlugin.NodeGetInfo(context.Background())
})
It("should return a correct NodeCSIInfo object", func() {
Expect(nodeInfo).ToNot(BeNil())
Expect(nodeInfo.NodeID).To(Equal("nodeid1"))
})
It("should not return an error", func() {
Expect(err).ToNot(HaveOccurred())
})
It("should create correct node info requests", func() {
Expect(nodeClient.NodeGetInfo).To(HaveLen(1))
})

})

0 comments on commit fe83529

Please sign in to comment.