-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworkflows_runs_histories_test.go
110 lines (96 loc) · 3.6 KB
/
workflows_runs_histories_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package coze
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWorkflowRunsHistories(t *testing.T) {
// Test Retrieve method
t.Run("Retrieve workflow run history success", func(t *testing.T) {
mockTransport := &mockTransport{
roundTripFunc: func(req *http.Request) (*http.Response, error) {
// Verify request method and path
assert.Equal(t, http.MethodGet, req.Method)
assert.Equal(t, "/v1/workflows/workflow1/run_histories/exec1", req.URL.Path)
// Return mock response
return mockResponse(http.StatusOK, &retrieveWorkflowRunsHistoriesResp{
RetrieveWorkflowRunsHistoriesResp: &RetrieveWorkflowRunsHistoriesResp{
Histories: []*WorkflowRunHistory{
{
ExecuteID: "exec1",
ExecuteStatus: WorkflowExecuteStatusSuccess,
BotID: "bot1",
ConnectorID: "1024",
ConnectorUid: "user1",
RunMode: WorkflowRunModeStreaming,
LogID: "log1",
CreateTime: 1234567890,
UpdateTime: 1234567891,
Output: `{"result": "success"}`,
ErrorCode: "0",
ErrorMessage: "",
DebugURL: "https://debug.example.com",
},
},
},
})
},
}
core := newCore(&http.Client{Transport: mockTransport}, ComBaseURL)
histories := newWorkflowRunsHistories(core)
resp, err := histories.Retrieve(context.Background(), &RetrieveWorkflowsRunsHistoriesReq{
WorkflowID: "workflow1",
ExecuteID: "exec1",
})
require.NoError(t, err)
assert.Equal(t, "test_log_id", resp.LogID())
require.Len(t, resp.Histories, 1)
history := resp.Histories[0]
assert.Equal(t, "exec1", history.ExecuteID)
assert.Equal(t, WorkflowExecuteStatusSuccess, history.ExecuteStatus)
assert.Equal(t, "bot1", history.BotID)
assert.Equal(t, "1024", history.ConnectorID)
assert.Equal(t, "user1", history.ConnectorUid)
assert.Equal(t, WorkflowRunModeStreaming, history.RunMode)
assert.Equal(t, "log1", history.LogID)
assert.Equal(t, 1234567890, history.CreateTime)
assert.Equal(t, 1234567891, history.UpdateTime)
assert.Equal(t, `{"result": "success"}`, history.Output)
assert.Equal(t, "0", history.ErrorCode)
assert.Empty(t, history.ErrorMessage)
assert.Equal(t, "https://debug.example.com", history.DebugURL)
})
// Test Retrieve method with error
t.Run("Retrieve workflow run history with error", func(t *testing.T) {
mockTransport := &mockTransport{
roundTripFunc: func(req *http.Request) (*http.Response, error) {
// Return error response
return mockResponse(http.StatusBadRequest, &baseResponse{})
},
}
core := newCore(&http.Client{Transport: mockTransport}, ComBaseURL)
histories := newWorkflowRunsHistories(core)
resp, err := histories.Retrieve(context.Background(), &RetrieveWorkflowsRunsHistoriesReq{
WorkflowID: "invalid_workflow",
ExecuteID: "invalid_exec",
})
require.Error(t, err)
assert.Nil(t, resp)
})
}
func TestWorkflowRunMode(t *testing.T) {
t.Run("WorkflowRunMode constants", func(t *testing.T) {
assert.Equal(t, WorkflowRunMode(0), WorkflowRunModeSynchronous)
assert.Equal(t, WorkflowRunMode(1), WorkflowRunModeStreaming)
assert.Equal(t, WorkflowRunMode(2), WorkflowRunModeAsynchronous)
})
}
func TestWorkflowExecuteStatus(t *testing.T) {
t.Run("WorkflowExecuteStatus constants", func(t *testing.T) {
assert.Equal(t, WorkflowExecuteStatus("Success"), WorkflowExecuteStatusSuccess)
assert.Equal(t, WorkflowExecuteStatus("Running"), WorkflowExecuteStatusRunning)
assert.Equal(t, WorkflowExecuteStatus("Fail"), WorkflowExecuteStatusFail)
})
}