util_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package clusters
  2. import "testing"
  3. const (
  4. testClusterInfoIDKey = "testClusterID"
  5. testClusterInfoNameKey = "testClusterName"
  6. testClusterProfileKey = "testProfile"
  7. testClusterProviderKey = "testProvider"
  8. testClusterAccountKey = "testAccount"
  9. testClusterProjectKey = "testProject"
  10. testClusterRegionKey = "testRegion"
  11. testClusterProvisionerKey = "testProvisioner"
  12. testClusterVersionKey = "testVersion"
  13. )
  14. func TestMapToClusterInfo(t *testing.T) {
  15. mapWOVersion := map[string]string{
  16. ClusterInfoIdKey: testClusterInfoIDKey,
  17. ClusterInfoNameKey: testClusterInfoNameKey,
  18. ClusterInfoProfileKey: testClusterProfileKey,
  19. ClusterInfoProviderKey: testClusterProviderKey,
  20. ClusterInfoAccountKey: testClusterAccountKey,
  21. ClusterInfoProjectKey: testClusterProjectKey,
  22. ClusterInfoRegionKey: testClusterRegionKey,
  23. ClusterInfoProvisionerKey: testClusterProvisionerKey,
  24. }
  25. expectedCIwoVersion := ClusterInfo{
  26. ID: testClusterInfoIDKey,
  27. Name: testClusterInfoNameKey,
  28. Profile: testClusterProfileKey,
  29. Provider: testClusterProviderKey,
  30. Account: testClusterAccountKey,
  31. Project: testClusterProjectKey,
  32. Region: testClusterRegionKey,
  33. Provisioner: testClusterProvisionerKey,
  34. }
  35. mapWVersion := map[string]string{
  36. ClusterInfoIdKey: testClusterInfoIDKey,
  37. ClusterInfoNameKey: testClusterInfoNameKey,
  38. ClusterInfoProfileKey: testClusterProfileKey,
  39. ClusterInfoProviderKey: testClusterProviderKey,
  40. ClusterInfoAccountKey: testClusterAccountKey,
  41. ClusterInfoProjectKey: testClusterProjectKey,
  42. ClusterInfoRegionKey: testClusterRegionKey,
  43. ClusterInfoProvisionerKey: testClusterProvisionerKey,
  44. ClusterInfoVersionKey: testClusterVersionKey,
  45. }
  46. expectedCIwVersion := ClusterInfo{
  47. ID: testClusterInfoIDKey,
  48. Name: testClusterInfoNameKey,
  49. Profile: testClusterProfileKey,
  50. Provider: testClusterProviderKey,
  51. Account: testClusterAccountKey,
  52. Project: testClusterProjectKey,
  53. Region: testClusterRegionKey,
  54. Provisioner: testClusterProvisionerKey,
  55. Version: testClusterVersionKey,
  56. }
  57. tests := []struct {
  58. name string
  59. input map[string]string
  60. expected ClusterInfo
  61. wantErr bool
  62. }{
  63. {
  64. name: "when version is not in the cluster info map",
  65. input: mapWOVersion,
  66. expected: expectedCIwoVersion,
  67. wantErr: false,
  68. },
  69. {
  70. name: "when version is in the cluster info map",
  71. input: mapWVersion,
  72. expected: expectedCIwVersion,
  73. wantErr: false,
  74. },
  75. }
  76. for _, tc := range tests {
  77. t.Run(tc.name, func(t *testing.T) {
  78. returnCI, err := MapToClusterInfo(tc.input)
  79. if (err != nil) != tc.wantErr {
  80. t.Errorf("MapToClusterInfo() error = %v, wantErr %v", err, tc.wantErr)
  81. return
  82. }
  83. if *returnCI != tc.expected {
  84. t.Errorf("MapToClusterInfo() expected = %v, got %v", tc.expected, returnCI)
  85. return
  86. }
  87. })
  88. }
  89. }