parse_test.go 811 B

123456789101112131415161718192021222324252627282930313233343536373839
  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, nil)
  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, nil)
  22. assert.ErrorIs(t, err, ErrNodeEmpty)
  23. }
  24. func readJsonFile(filePath string) string {
  25. file, err := os.Open(filePath)
  26. if err != nil {
  27. panic(err)
  28. }
  29. defer file.Close()
  30. content, err := io.ReadAll(file)
  31. if err != nil {
  32. panic(err)
  33. }
  34. return string(content)
  35. }