costmodel_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package costmodel
  2. import (
  3. "testing"
  4. )
  5. func Test_CostData_GetController_CronJob(t *testing.T) {
  6. cases := []struct {
  7. name string
  8. cd CostData
  9. expectedName string
  10. expectedKind string
  11. expectedHasController bool
  12. }{
  13. {
  14. name: "batch/v1beta1 CronJob Job name",
  15. cd: CostData{
  16. // batch/v1beta1 CronJobs create Jobs with a 10 character
  17. // timestamp appended to the end of the name.
  18. //
  19. // It looks like this:
  20. // CronJob: cronjob-1
  21. // Job: cronjob-1-1651057200
  22. // Pod: cronjob-1-1651057200-mf5c9
  23. Jobs: []string{"cronjob-1-1651057200"},
  24. },
  25. expectedName: "cronjob-1",
  26. expectedKind: "job",
  27. expectedHasController: true,
  28. },
  29. {
  30. name: "batch/v1 CronJob Job name",
  31. cd: CostData{
  32. // batch/v1CronJobs create Jobs with an 8 character timestamp
  33. // appended to the end of the name.
  34. //
  35. // It looks like this:
  36. // CronJob: cj-v1
  37. // Job: cj-v1-27517770
  38. // Pod: cj-v1-27517770-xkrgn
  39. Jobs: []string{"cj-v1-27517770"},
  40. },
  41. expectedName: "cj-v1",
  42. expectedKind: "job",
  43. expectedHasController: true,
  44. },
  45. }
  46. for _, c := range cases {
  47. t.Run(c.name, func(t *testing.T) {
  48. name, kind, hasController := c.cd.GetController()
  49. if name != c.expectedName {
  50. t.Errorf("Name mismatch. Expected: %s. Got: %s", c.expectedName, name)
  51. }
  52. if kind != c.expectedKind {
  53. t.Errorf("Kind mismatch. Expected: %s. Got: %s", c.expectedKind, kind)
  54. }
  55. if hasController != c.expectedHasController {
  56. t.Errorf("HasController mismatch. Expected: %t. Got: %t", c.expectedHasController, hasController)
  57. }
  58. })
  59. }
  60. }