@@ -42,6 +42,65 @@ func TestUpsertFunctions(t *testing.T) {
42
42
era .eszip = & MockBundler {}
43
43
})
44
44
45
+ t .Run ("deploys with bulk update" , func (t * testing.T ) {
46
+ // Setup mock api
47
+ defer gock .OffAll ()
48
+ gock .New (mockApiHost ).
49
+ Get ("/v1/projects/" + mockProject + "/functions" ).
50
+ Reply (http .StatusOK ).
51
+ JSON ([]api.FunctionResponse {{Slug : "test-a" }})
52
+ gock .New (mockApiHost ).
53
+ Patch ("/v1/projects/" + mockProject + "/functions/test-a" ).
54
+ Reply (http .StatusOK ).
55
+ JSON (api.FunctionResponse {Slug : "test-a" })
56
+ gock .New (mockApiHost ).
57
+ Post ("/v1/projects/" + mockProject + "/functions/test-b" ).
58
+ Reply (http .StatusOK ).
59
+ JSON (api.FunctionResponse {Slug : "test-b" })
60
+ gock .New (mockApiHost ).
61
+ Put ("/v1/projects/" + mockProject + "/functions" ).
62
+ ReplyError (errors .New ("network error" ))
63
+ gock .New (mockApiHost ).
64
+ Put ("/v1/projects/" + mockProject + "/functions" ).
65
+ Reply (http .StatusServiceUnavailable )
66
+ gock .New (mockApiHost ).
67
+ Put ("/v1/projects/" + mockProject + "/functions" ).
68
+ Reply (http .StatusOK ).
69
+ JSON (api.V1BulkUpdateFunctionsResponse {})
70
+ // Run test
71
+ err := client .UpsertFunctions (context .Background (), config.FunctionConfig {
72
+ "test-a" : {},
73
+ "test-b" : {},
74
+ })
75
+ // Check error
76
+ assert .NoError (t , err )
77
+ assert .Empty (t , apitest .ListUnmatchedRequests ())
78
+ })
79
+
80
+ t .Run ("handles concurrent deploy" , func (t * testing.T ) {
81
+ // Setup mock api
82
+ defer gock .OffAll ()
83
+ gock .New (mockApiHost ).
84
+ Get ("/v1/projects/" + mockProject + "/functions" ).
85
+ Reply (http .StatusOK ).
86
+ JSON ([]api.FunctionResponse {})
87
+ gock .New (mockApiHost ).
88
+ Post ("/v1/projects/" + mockProject + "/functions" ).
89
+ Reply (http .StatusBadRequest ).
90
+ BodyString ("Duplicated function slug" )
91
+ gock .New (mockApiHost ).
92
+ Patch ("/v1/projects/" + mockProject + "/functions/test" ).
93
+ Reply (http .StatusOK ).
94
+ JSON (api.FunctionResponse {Slug : "test" })
95
+ // Run test
96
+ err := client .UpsertFunctions (context .Background (), config.FunctionConfig {
97
+ "test" : {},
98
+ })
99
+ // Check error
100
+ assert .NoError (t , err )
101
+ assert .Empty (t , apitest .ListUnmatchedRequests ())
102
+ })
103
+
45
104
t .Run ("retries on network failure" , func (t * testing.T ) {
46
105
// Setup mock api
47
106
defer gock .OffAll ()
@@ -84,6 +143,7 @@ func TestUpsertFunctions(t *testing.T) {
84
143
})
85
144
// Check error
86
145
assert .NoError (t , err )
146
+ assert .Empty (t , apitest .ListUnmatchedRequests ())
87
147
})
88
148
89
149
t .Run ("retries on update failure" , func (t * testing.T ) {
@@ -109,5 +169,6 @@ func TestUpsertFunctions(t *testing.T) {
109
169
})
110
170
// Check error
111
171
assert .NoError (t , err )
172
+ assert .Empty (t , apitest .ListUnmatchedRequests ())
112
173
})
113
174
}
0 commit comments