-
Notifications
You must be signed in to change notification settings - Fork 6
/
wait_test.go
62 lines (49 loc) · 1.59 KB
/
wait_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
package transloadit
import (
"context"
"strings"
"testing"
"time"
)
func TestWaitForAssembly(t *testing.T) {
t.Parallel()
client := setup(t)
assembly := NewAssembly()
assembly.AddStep("convert", map[string]interface{}{
"robot": "/html/convert",
"url": "https://transloadit.com/",
})
info, err := client.StartAssembly(ctx, assembly)
if err != nil {
t.Fatal(err)
}
if info.AssemblyURL == "" {
t.Fatal("response doesn't contain assembly_url")
}
finishedInfo, err := client.WaitForAssembly(ctx, info)
if err != nil {
t.Fatal(err)
}
// Assembly completed
if finishedInfo.AssemblyID != info.AssemblyID {
t.Fatal("unmatching assembly ids")
}
}
func TestWaitForAssembly_Cancel(t *testing.T) {
t.Parallel()
client := setup(t)
ctx, cancel := context.WithTimeout(ctx, 100*time.Nanosecond)
defer cancel()
_, err := client.WaitForAssembly(ctx, &AssemblyInfo{
AssemblySSLURL: "https://api2.transloadit.com/assemblies/foo",
})
// Go 1.8 and Go 1.7 have different error messages if a request get canceled.
// Therefore we test for both cases.
// Sometimes, a "dial tcp: i/o timeout" error is thrown if the context times
// out shortly before the dialing is started, see:
// https://sourcegraph.com/github.com/golang/go@d6a27e8edcd992b36446c5021a3c7560d983e9a6/-/blob/src/net/dial.go#L123-125
// Therefore we also accept i/o timeouts as errors here.
if !strings.Contains(err.Error(), "context deadline exceeded") && !strings.Contains(err.Error(), "request canceled") && !strings.Contains(err.Error(), "i/o timeout") {
t.Fatalf("operation's deadline should be exceeded: %s", err)
}
}