MCPcopy Create free account
hub / github.com/dolthub/doltgresql / CreateServerLocalWithPort

Function CreateServerLocalWithPort

testing/go/framework.go:435–465  ·  view source on GitHub ↗

CreateServerLocalWithPort creates a server using the local file system at [os.TempDir]. A Connection is returned to |database| at 127.0.0.1:|port|. The server will close when the connection is closed or lost. The returned [svcs.Controller] may be used to wait for the server to stop.

(t *testing.T, database string, port int)

Source from the content-addressed store, hash-verified

433// |database| at 127.0.0.1:|port|. The server will close when the connection is closed or lost. The returned
434// [svcs.Controller] may be used to wait for the server to stop.
435func CreateServerLocalWithPort(t *testing.T, database string, port int) (context.Context, *Connection, *svcs.Controller) {
436 // We avoid using [T.TempDir] because it results in a file lock conflict on Windows. [T.TempDir] registers a
437 // [T.Cleanup] function that runs without checking the [svcs.Controller] and it cannot be overwritten.
438 // TODO(elianddb): Setup an optional [T.Cleanup] function for the temporary directory. Our default setup for now is
439 // preferable for debugging the database after a failure.
440 // t.Name() contains "/" for subtests, which os.MkdirTemp rejects as a path separator in the pattern.
441 safeName := strings.ReplaceAll(t.Name(), "/", "_")
442 dbDir, err := os.MkdirTemp(os.TempDir(), safeName)
443 require.NoError(t, err)
444 fileSys, err := filesys.LocalFilesysWithWorkingDir(dbDir)
445 require.NoError(t, err)
446
447 ctx := context.Background()
448 doltEnv := env.Load(ctx, env.GetCurrentUserHomeDir, fileSys, doltdb.LocalDirDoltDB, dserver.Version)
449
450 controller, err := dserver.RunOnDisk(ctx, &servercfg.DoltgresConfig{
451 DoltgresConfig: cfgdetails.DoltgresConfig{
452 ListenerConfig: &cfgdetails.DoltgresListenerConfig{
453 PortNumber: &port,
454 HostStr: &serverHost,
455 },
456 LogLevelStr: &testServerLogLevel,
457 },
458 }, doltEnv)
459 require.NoError(t, err)
460 auth.ClearDatabase()
461 fmt.Printf("port is %d\n", port)
462
463 connection := newTestDatabaseConnection(t, ctx, database, serverHost, port)
464 return ctx, connection, controller
465}
466
467// newTestDatabaseConnection returns a Connection to the test |database| at |host|:|port|. If the |database| provided
468// does not exist, it will be automatically created.

Callers 2

RunScriptFunction · 0.85
runBackupTestFunction · 0.85

Calls 5

ClearDatabaseFunction · 0.92
TempDirMethod · 0.80
PrintfMethod · 0.80
NameMethod · 0.65

Tested by 1

runBackupTestFunction · 0.68