forked from moby/swarmkit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add foundational test code for node agent
Signed-off-by: Ameya Gawde <agawde@mirantis.com>
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
}) | ||
|
||
}) |