workflow_template_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package test
  2. import (
  3. "git.sxidc.com/go-tools/argo-api"
  4. "git.sxidc.com/go-tools/argo-api/client"
  5. "github.com/pkg/errors"
  6. "testing"
  7. )
  8. func TestWorkflowTemplate(t *testing.T) {
  9. err := argo.Init(kubeConfig)
  10. if err != nil {
  11. t.Fatalf("%+v\n", err)
  12. }
  13. defer argo.Destroy()
  14. err = argo.GetInstance().LintWorkflowTemplate(client.LintWorkflowTemplateParams{
  15. Namespace: namespace,
  16. TemplateDefinition: templateYamlStr,
  17. })
  18. if err != nil {
  19. t.Fatalf("%+v\n", err)
  20. }
  21. err = argo.GetInstance().CreateWorkflowTemplate(client.CreateWorkflowTemplateParams{
  22. Namespace: namespace,
  23. TemplateDefinition: templateYamlStr,
  24. })
  25. if err != nil {
  26. t.Fatalf("%+v\n", err)
  27. }
  28. defer func() {
  29. err := argo.GetInstance().DeleteWorkflowTemplate(client.DeleteWorkflowTemplateParams{
  30. Namespace: namespace,
  31. Name: workflowTemplateName,
  32. })
  33. if err != nil {
  34. t.Fatalf("%+v\n", err)
  35. }
  36. }()
  37. wfts, err := argo.GetInstance().GetWorkflowTemplatesInNamespace(client.GetWorkflowTemplatesInNamespaceParams{
  38. Namespace: namespace,
  39. })
  40. if err != nil {
  41. t.Fatalf("%+v\n", err)
  42. }
  43. if len(wfts) != 1 {
  44. t.Fatalf("%+v\n", errors.Errorf("数量不一致: %v", len(wfts)))
  45. }
  46. wft, err := argo.GetInstance().GetWorkflowTemplate(client.GetWorkflowTemplateParams{
  47. Namespace: namespace,
  48. Name: workflowTemplateName,
  49. })
  50. if err != nil {
  51. t.Fatalf("%+v\n", err)
  52. }
  53. if wft.Namespace != wfts[0].Namespace {
  54. t.Fatalf("%+v\n", errors.Errorf("命名空间不一致: one: %s other: %s", wft.Namespace, wfts[0].Namespace))
  55. }
  56. if wft.Name != wfts[0].Name {
  57. t.Fatalf("%+v\n", errors.Errorf("名称不一致: one: %s other: %s", wft.Name, wfts[0].Name))
  58. }
  59. err = argo.GetInstance().UpdateWorkflowTemplate(client.UpdateWorkflowTemplateParams{
  60. Namespace: namespace,
  61. Name: workflowTemplateName,
  62. WorkflowTemplate: wft,
  63. })
  64. if err != nil {
  65. t.Fatalf("%+v\n", err)
  66. }
  67. }