@@ -3,11 +3,13 @@ package porcelain
3
3
import (
4
4
"bytes"
5
5
gocontext "context"
6
+ "fmt"
6
7
"io/ioutil"
7
8
"net/http"
8
9
"net/http/httptest"
9
10
"net/url"
10
11
"os"
12
+ "path"
11
13
"path/filepath"
12
14
"strings"
13
15
"testing"
@@ -200,6 +202,91 @@ func TestUploadFiles_Cancelation(t *testing.T) {
200
202
require .ErrorIs (t , err , gocontext .Canceled )
201
203
}
202
204
205
+ func TestBundle (t * testing.T ) {
206
+ functions , err := bundle ("../internal/data" , mockObserver {})
207
+
208
+ if err != nil {
209
+ t .Fatalf ("unexpected error bundling functions: %v" , err )
210
+ }
211
+
212
+ if len (functions .Files ) != 3 {
213
+ t .Fatalf ("unexpected number of functions, expected=3, got=%d" , len (functions .Files ))
214
+ }
215
+
216
+ jsFunction := functions .Files ["hello-js-function-test" ]
217
+ pyFunction := functions .Files ["hello-py-function-test" ]
218
+ rsFunction := functions .Files ["hello-rs-function-test" ]
219
+
220
+ if jsFunction .Runtime != "js" {
221
+ t .Fatalf ("unexpected runtime, expected='js', got='%v'" , jsFunction .Runtime )
222
+ }
223
+
224
+ if pyFunction .Runtime != "py" {
225
+ t .Fatalf ("unexpected runtime, expected='py', got='%v'" , pyFunction .Runtime )
226
+ }
227
+
228
+ if rsFunction .Runtime != "rs" {
229
+ t .Fatalf ("unexpected runtime, expected='rs', got='%v'" , rsFunction .Runtime )
230
+ }
231
+ }
232
+
233
+ func TestBundleWithManifest (t * testing.T ) {
234
+ cwd , _ := os .Getwd ()
235
+ basePath := path .Join (filepath .Dir (cwd ), "internal" , "data" )
236
+ jsFunctionPath := strings .Replace (filepath .Join (basePath , "hello-js-function-test.zip" ), "\\ " , "/" , - 1 )
237
+ pyFunctionPath := strings .Replace (filepath .Join (basePath , "hello-py-function-test.zip" ), "\\ " , "/" , - 1 )
238
+ manifestPath := path .Join (basePath , "manifest.json" )
239
+ manifestFile := fmt .Sprintf (`{
240
+ "functions": [
241
+ {
242
+ "path": "%s",
243
+ "runtime": "a-runtime",
244
+ "mainFile": "/some/path/hello-js-function-test.js",
245
+ "name": "hello-js-function-test"
246
+ },
247
+ {
248
+ "path": "%s",
249
+ "runtime": "some-other-runtime",
250
+ "mainFile": "/some/path/hello-py-function-test",
251
+ "name": "hello-py-function-test"
252
+ }
253
+ ],
254
+ "version": 1
255
+ }` , jsFunctionPath , pyFunctionPath )
256
+
257
+ err := ioutil .WriteFile (manifestPath , []byte (manifestFile ), 0644 )
258
+ defer os .Remove (manifestPath )
259
+
260
+ if err != nil {
261
+ t .Fatal ("could not create manifest file" )
262
+ }
263
+
264
+ functions , err := bundle ("../internal/data" , mockObserver {})
265
+
266
+ t .Log (functions )
267
+
268
+ if err != nil {
269
+ t .Fatalf ("unexpected error bundling functions: %v" , err )
270
+ }
271
+
272
+ if len (functions .Files ) != 2 {
273
+ t .Fatalf ("unexpected number of functions, expected=2, got=%d" , len (functions .Files ))
274
+ }
275
+
276
+ jsFunction := functions .Files ["hello-js-function-test" ]
277
+ expectedJsFunctionRuntime := "a-runtime"
278
+ pyFunction := functions .Files ["hello-py-function-test" ]
279
+ expectedPyFunctionRuntime := "some-other-runtime"
280
+
281
+ if jsFunction .Runtime != expectedJsFunctionRuntime {
282
+ t .Fatalf ("unexpected runtime, expected='%s', got='%v'" , expectedJsFunctionRuntime , jsFunction .Runtime )
283
+ }
284
+
285
+ if pyFunction .Runtime != expectedPyFunctionRuntime {
286
+ t .Fatalf ("unexpected runtime, expected='%s', got='%v'" , expectedPyFunctionRuntime , pyFunction .Runtime )
287
+ }
288
+ }
289
+
203
290
func TestReadZipRuntime (t * testing.T ) {
204
291
runtime , err := readZipRuntime ("../internal/data/hello-rs-function-test.zip" )
205
292
if err != nil {
0 commit comments