awsprovider_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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: "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: "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: "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. for _, tt := range tests {
  54. t.Run(tt.name, func(t *testing.T) {
  55. k := &awsKey{
  56. Labels: tt.fields.Labels,
  57. ProviderID: tt.fields.ProviderID,
  58. }
  59. if got := k.getUsageType(tt.args.labels); got != tt.want {
  60. t.Errorf("getUsageType() = %v, want %v", got, tt.want)
  61. }
  62. })
  63. }
  64. }