MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / javaScriptFile

Function javaScriptFile

rest/config_test.go:1597–1611  ·  view source on GitHub ↗

javaScriptFile returns a callable function to create a JavaScript file on the disk with the given JavaScript source and returns a teardown function to remove the file after its use.

(t *testing.T, js string)

Source from the content-addressed store, hash-verified

1595// javaScriptFile returns a callable function to create a JavaScript file on the disk with the
1596// given JavaScript source and returns a teardown function to remove the file after its use.
1597func javaScriptFile(t *testing.T, js string) func() (path string, teardownFn func()) {
1598 return func() (path string, teardownFn func()) {
1599 file, err := os.CreateTemp("", "*.js")
1600 require.NoError(t, err, "Error creating JavaScript file")
1601 _, err = file.Write([]byte(js))
1602 require.NoError(t, err, "Error writing to JavaScript file")
1603 path = file.Name()
1604 teardownFn = func() {
1605 assert.NoError(t, file.Close(), "Error closing file: %s ", path)
1606 assert.NoError(t, os.Remove(path), "Error removing file: %s ", path)
1607 assert.False(t, base.FileExists(path), "File %s should be removed", path)
1608 }
1609 return path, teardownFn
1610 }
1611}
1612
1613// emptyJavaScriptFile returns a callable function to create an empty file on the disk
1614// and returns a teardown function to remove the file after its use.

Calls 5

FileExistsFunction · 0.92
NameMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected