MCPcopy
hub / github.com/pocketbase/pocketbase / TestBindFilesystem

Function TestBindFilesystem

plugins/jsvm/binds_test.go:999–1117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

997}
998
999func TestBindFilesystem(t *testing.T) {
1000 app, _ := tests.NewTestApp()
1001 defer app.Cleanup()
1002
1003 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1004 if r.URL.Path == "/error" {
1005 w.WriteHeader(http.StatusInternalServerError)
1006 }
1007
1008 fmt.Fprintf(w, "test")
1009 }))
1010 defer srv.Close()
1011
1012 tmpDir, err := os.MkdirTemp("", "jsvm")
1013 if err != nil {
1014 t.Fatal(err)
1015 }
1016 defer os.RemoveAll(tmpDir)
1017
1018 vm := goja.New()
1019 vm.Set("mh", &multipart.FileHeader{Filename: "test"})
1020 vm.Set("tmpDir", tmpDir)
1021 vm.Set("testFile", filepath.Join(app.DataDir(), "data.db"))
1022 vm.Set("baseURL", srv.URL)
1023 BindCore(vm)
1024 BindFilesystem(vm)
1025
1026 testBindsCount(vm, "$filesystem", 6, t)
1027
1028 // s3
1029 {
1030 v, err := vm.RunString(`$filesystem.s3("bucketName", "region", "endpoint", "accessKey", "secretKey", true)`)
1031 if err != nil {
1032 t.Fatal(err)
1033 }
1034
1035 fsys, ok := v.Export().(*filesystem.System)
1036 if !ok {
1037 t.Fatalf("[s3] Expected System instance got %v", fsys)
1038 }
1039 }
1040
1041 // local
1042 {
1043 v, err := vm.RunString(`$filesystem.local(tmpDir)`)
1044 if err != nil {
1045 t.Fatal(err)
1046 }
1047
1048 fsys, ok := v.Export().(*filesystem.System)
1049 if !ok {
1050 t.Fatalf("[s3] Expected System instance got %v", fsys)
1051 }
1052 }
1053
1054 // fileFromPath
1055 {
1056 v, err := vm.RunString(`$filesystem.fileFromPath(testFile)`)

Callers

nothing calls this directly

Calls 10

CleanupMethod · 0.95
NewTestAppFunction · 0.92
BindCoreFunction · 0.85
BindFilesystemFunction · 0.85
testBindsCountFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.65
DataDirMethod · 0.65
WriteHeaderMethod · 0.45
RemoveAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…