parse_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package approve_former
  2. import (
  3. "fmt"
  4. "git.sxidc.com/go-tools/argo-api"
  5. "git.sxidc.com/go-tools/argo-api/client"
  6. "github.com/stretchr/testify/assert"
  7. "io"
  8. "os"
  9. "testing"
  10. )
  11. // TestParseFlowFromJson 测试整体结构解析
  12. func TestParseFlowFromJson(t *testing.T) {
  13. // 测试结构解析
  14. frontJson := readJsonFile("./front_json/full.json")
  15. argoTmp, err := ParseFlowFromJson("1", "测试流程", "duyong", frontJson, "")
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. fmt.Println(argoTmp)
  20. }
  21. func TestParseEmptyFlowFromJson(t *testing.T) {
  22. frontJson := readJsonFile("./front_json/empty.json")
  23. _, err := ParseFlowFromJson("2", "测试流程", "duyong", frontJson, "")
  24. assert.ErrorIs(t, err, ErrNodeEmpty)
  25. }
  26. func TestParseSingleFlowFromJsonFile(t *testing.T) {
  27. frontJson := readJsonFile("./front_json/approval_one_user.json")
  28. argObj := `{"props":{"labelWidth":100,"labelPosition":"top","size":"large"},"formItems":[],"span":12}`
  29. argoTmp, err := ParseFlowFromJson("3", "single", "duyong", frontJson, argObj)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. fmt.Println(argoTmp)
  34. }
  35. func TestGetParsedWorkfolw(t *testing.T) {
  36. err := argo.Init("/Users/duyong/WorkPlace/fangshi/meta-business/argo/test/k3s.yaml")
  37. if err != nil {
  38. t.Fatalf("%+v\n", err)
  39. }
  40. defer argo.Destroy()
  41. wfs, err := argo.GetInstance().GetWorkflowsInNamespace(client.GetWorkflowsInNamespaceParams{
  42. Namespace: "default",
  43. })
  44. if err != nil {
  45. t.Fatalf("%+v\n", err)
  46. }
  47. fmt.Println(wfs)
  48. }
  49. func readJsonFile(filePath string) string {
  50. file, err := os.Open(filePath)
  51. if err != nil {
  52. panic(err)
  53. }
  54. defer file.Close()
  55. content, err := io.ReadAll(file)
  56. if err != nil {
  57. panic(err)
  58. }
  59. return string(content)
  60. }