parse_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package approve_former
  2. import (
  3. "fmt"
  4. "github.com/stretchr/testify/assert"
  5. "io"
  6. "os"
  7. "testing"
  8. )
  9. // TestParseFlowFromJson 测试整体结构解析
  10. func TestParseFlowFromJson(t *testing.T) {
  11. // 测试结构解析
  12. frontJson := readJsonFile("./front_json/full.json")
  13. argoTmp, err := ParseFlowFromJson("full", "测试流程", frontJson, "")
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. fmt.Println(argoTmp)
  18. }
  19. func TestParseEmptyFlowFromJson(t *testing.T) {
  20. frontJson := readJsonFile("./front_json/empty.json")
  21. _, err := ParseFlowFromJson("empty", "测试流程", frontJson, "")
  22. assert.ErrorIs(t, err, ErrNodeEmpty)
  23. }
  24. func TestParseSingleFlowFromJsonFile(t *testing.T) {
  25. frontJson := readJsonFile("./front_json/approval_one_user.json")
  26. argoTmp, err := ParseFlowFromJson("single", "测试流程", frontJson, "")
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. fmt.Println(argoTmp)
  31. }
  32. func readJsonFile(filePath string) string {
  33. file, err := os.Open(filePath)
  34. if err != nil {
  35. panic(err)
  36. }
  37. defer file.Close()
  38. content, err := io.ReadAll(file)
  39. if err != nil {
  40. panic(err)
  41. }
  42. return string(content)
  43. }