package approve_former import ( "fmt" "git.sxidc.com/go-tools/argo-api" "git.sxidc.com/go-tools/argo-api/client" "github.com/stretchr/testify/assert" "io" "os" "testing" ) // TestParseFlowFromJson 测试整体结构解析 func TestParseFlowFromJson(t *testing.T) { // 测试结构解析 frontJson := readJsonFile("./front_json/full.json") argoTmp, err := ParseFlowFromJson("1", "测试流程", "duyong", frontJson, "") if err != nil { t.Fatal(err) } fmt.Println(argoTmp) } func TestParseEmptyFlowFromJson(t *testing.T) { frontJson := readJsonFile("./front_json/empty.json") _, err := ParseFlowFromJson("2", "测试流程", "duyong", frontJson, "") assert.ErrorIs(t, err, ErrNodeEmpty) } func TestParseSingleFlowFromJsonFile(t *testing.T) { frontJson := readJsonFile("./front_json/approval_one_user.json") argObj := `{"props":{"labelWidth":100,"labelPosition":"top","size":"large"},"formItems":[],"span":12}` argoTmp, err := ParseFlowFromJson("3", "single", "duyong", frontJson, argObj) if err != nil { t.Fatal(err) } fmt.Println(argoTmp) } func TestGetParsedWorkfolw(t *testing.T) { err := argo.Init("/Users/duyong/WorkPlace/fangshi/meta-business/argo/test/k3s.yaml") if err != nil { t.Fatalf("%+v\n", err) } defer argo.Destroy() wfs, err := argo.GetInstance().GetWorkflowsInNamespace(client.GetWorkflowsInNamespaceParams{ Namespace: "default", }) if err != nil { t.Fatalf("%+v\n", err) } fmt.Println(wfs) } func readJsonFile(filePath string) string { file, err := os.Open(filePath) if err != nil { panic(err) } defer file.Close() content, err := io.ReadAll(file) if err != nil { panic(err) } return string(content) }