awsprovider_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package cloud
  2. import "testing"
  3. func Test_awsKey_getUsageType(t *testing.T) {
  4. type fields struct {
  5. Labels map[string]string
  6. ProviderID string
  7. }
  8. type args struct {
  9. labels map[string]string
  10. }
  11. tests := []struct {
  12. name string
  13. fields fields
  14. args args
  15. want string
  16. }{
  17. {
  18. // test with no labels should return false
  19. name: "Label does not have the capacityType label associated with it",
  20. args: args{
  21. labels: map[string]string{},
  22. },
  23. want: "",
  24. },
  25. {
  26. name: "EKS label with a capacityType set to empty string should return empty string",
  27. args: args{
  28. labels: map[string]string{
  29. EKSCapacityTypeLabel: "",
  30. },
  31. },
  32. want: "",
  33. },
  34. {
  35. name: "EKS label with capacityType set to a random value should return empty string",
  36. args: args{
  37. labels: map[string]string{
  38. EKSCapacityTypeLabel: "TEST_ME",
  39. },
  40. },
  41. want: "",
  42. },
  43. {
  44. name: "EKS label with capacityType set to spot should return spot",
  45. args: args{
  46. labels: map[string]string{
  47. EKSCapacityTypeLabel: EKSCapacitySpotTypeValue,
  48. },
  49. },
  50. want: PreemptibleType,
  51. },
  52. {
  53. name: "Karpenter label with a capacityType set to empty string should return empty string",
  54. args: args{
  55. labels: map[string]string{
  56. KarpenterCapacityTypeLabel: "",
  57. },
  58. },
  59. want: "",
  60. },
  61. {
  62. name: "Karpenter label with capacityType set to a random value should return empty string",
  63. args: args{
  64. labels: map[string]string{
  65. KarpenterCapacityTypeLabel: "TEST_ME",
  66. },
  67. },
  68. want: "",
  69. },
  70. {
  71. name: "Karpenter label with capacityType set to spot should return spot",
  72. args: args{
  73. labels: map[string]string{
  74. KarpenterCapacityTypeLabel: KarpenterCapacitySpotTypeValue,
  75. },
  76. },
  77. want: PreemptibleType,
  78. },
  79. }
  80. for _, tt := range tests {
  81. t.Run(tt.name, func(t *testing.T) {
  82. k := &awsKey{
  83. Labels: tt.fields.Labels,
  84. ProviderID: tt.fields.ProviderID,
  85. }
  86. if got := k.getUsageType(tt.args.labels); got != tt.want {
  87. t.Errorf("getUsageType() = %v, want %v", got, tt.want)
  88. }
  89. })
  90. }
  91. }