-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreplaytest_test.go
More file actions
105 lines (94 loc) · 2.69 KB
/
replaytest_test.go
File metadata and controls
105 lines (94 loc) · 2.69 KB
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
package tempts
import (
"encoding/json"
"fmt"
"testing"
)
func TestFilterWorkflowHistoriesBundle(t *testing.T) {
makeBundle := func(name string, ids ...string) []byte {
data := historiesData{WorkflowName: name}
for _, id := range ids {
data.Histories = append(data.Histories, historyWithMetadata{
WorkflowID: id,
RunID: "run-" + id,
HistoryBytes: []byte("fake"),
})
}
b, err := json.Marshal(data)
if err != nil {
t.Fatal(err)
}
return b
}
t.Run("keeps only compatible executions", func(t *testing.T) {
bundle := makeBundle("MyWorkflow", "wf-1", "wf-2", "wf-3")
filtered, count, err := FilterWorkflowHistoriesBundle(bundle, func(single []byte) error {
var d historiesData
if err := json.Unmarshal(single, &d); err != nil {
return err
}
if d.Histories[0].WorkflowID == "wf-2" {
return fmt.Errorf("incompatible")
}
return nil
})
if err != nil {
t.Fatal(err)
}
if count != 2 {
t.Fatalf("expected 2 compatible, got %d", count)
}
var result historiesData
if err := json.Unmarshal(filtered, &result); err != nil {
t.Fatal(err)
}
if result.WorkflowName != "MyWorkflow" {
t.Fatalf("expected workflow name MyWorkflow, got %s", result.WorkflowName)
}
if len(result.Histories) != 2 {
t.Fatalf("expected 2 histories, got %d", len(result.Histories))
}
if result.Histories[0].WorkflowID != "wf-1" || result.Histories[1].WorkflowID != "wf-3" {
t.Fatalf("unexpected workflow IDs: %s, %s", result.Histories[0].WorkflowID, result.Histories[1].WorkflowID)
}
})
t.Run("returns error when all executions fail", func(t *testing.T) {
bundle := makeBundle("MyWorkflow", "wf-1", "wf-2")
_, n, err := FilterWorkflowHistoriesBundle(bundle, func(single []byte) error {
return fmt.Errorf("incompatible")
})
if err == nil {
t.Fatal("expected error, got nil")
}
if n != 2 {
t.Fatalf("expected total count 2, got %d", n)
}
})
t.Run("returns error on malformed JSON", func(t *testing.T) {
_, _, err := FilterWorkflowHistoriesBundle([]byte("not json"), func(single []byte) error {
return nil
})
if err == nil {
t.Fatal("expected error, got nil")
}
})
t.Run("keeps all when all pass", func(t *testing.T) {
bundle := makeBundle("MyWorkflow", "wf-1", "wf-2", "wf-3")
filtered, count, err := FilterWorkflowHistoriesBundle(bundle, func(single []byte) error {
return nil
})
if err != nil {
t.Fatal(err)
}
if count != 3 {
t.Fatalf("expected 3 compatible, got %d", count)
}
var result historiesData
if err := json.Unmarshal(filtered, &result); err != nil {
t.Fatal(err)
}
if len(result.Histories) != 3 {
t.Fatalf("expected 3 histories, got %d", len(result.Histories))
}
})
}