package tests import ( "apigo.cloud/git/apigo/gojs" "apigo.cloud/git/apigo/plugin" _ "apigo.cloud/git/apigo/plugins/file" "testing" ) func TestFile(t *testing.T) { rt := gojs.New(nil, nil) defer rt.Close() gojs.SetPluginsConfig(map[string]plugin.Config{ "file": { "allowPaths": []string{ "testData", }, "allowExtensions": []string{ ".txt", }, }, }) r, err, _ := rt.Run(` try{ file.write('testData/aaa.txt', '123') if(file.read('testData/aaa.txt')!=='123') throw new Error('write and read file') let f = file.open('testData/aaa.txt') try{ f.write('22') f.seekStart() if(f.read(20)!=='223') throw new Error('write file by seek') }catch(ex){ throw ex }finally{ f.close() } file.saveJson('testData/bbb.txt', {bbb:234}) if(file.loadJson('testData/bbb.txt').bbb!==234) throw new Error('write and read json') files = file.list('testData', 'name') if( files.length !== 2 || files[1].name !== 'bbb.txt' ) throw new Error('list file, count: '+files.length+' name: '+files[1].name) }catch(ex){ throw ex }finally{ file.remove('testData') } return true `) Test(t, "file", r == true && err == nil, r, err) }