node_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package convert
  2. import (
  3. "testing"
  4. types "github.com/docker/docker/api/types/swarm"
  5. swarmapi "github.com/moby/swarmkit/v2/api"
  6. "gotest.tools/v3/assert"
  7. )
  8. // TestNodeCSIInfoFromGRPC tests that conversion of the NodeCSIInfo from the
  9. // gRPC to the Docker types is correct.
  10. func TestNodeCSIInfoFromGRPC(t *testing.T) {
  11. node := &swarmapi.Node{
  12. ID: "someID",
  13. Description: &swarmapi.NodeDescription{
  14. CSIInfo: []*swarmapi.NodeCSIInfo{
  15. {
  16. PluginName: "plugin1",
  17. NodeID: "p1n1",
  18. MaxVolumesPerNode: 1,
  19. },
  20. {
  21. PluginName: "plugin2",
  22. NodeID: "p2n1",
  23. MaxVolumesPerNode: 2,
  24. AccessibleTopology: &swarmapi.Topology{
  25. Segments: map[string]string{
  26. "a": "1",
  27. "b": "2",
  28. },
  29. },
  30. },
  31. },
  32. },
  33. }
  34. expected := []types.NodeCSIInfo{
  35. {
  36. PluginName: "plugin1",
  37. NodeID: "p1n1",
  38. MaxVolumesPerNode: 1,
  39. },
  40. {
  41. PluginName: "plugin2",
  42. NodeID: "p2n1",
  43. MaxVolumesPerNode: 2,
  44. AccessibleTopology: &types.Topology{
  45. Segments: map[string]string{
  46. "a": "1",
  47. "b": "2",
  48. },
  49. },
  50. },
  51. }
  52. actual := NodeFromGRPC(*node)
  53. assert.DeepEqual(t, actual.Description.CSIInfo, expected)
  54. }