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

Function MakeServer

integration-tests/go-sql-server-driver/testdef.go:365–429  ·  view source on GitHub ↗
(t *testing.T, dc driver.DoltCmdable, cwd string, s *driver.Server, resources *DynamicResources, manualOps ...driver.SqlServerOpt)

Source from the content-addressed store, hash-verified

363}
364
365func MakeServer(t *testing.T, dc driver.DoltCmdable, cwd string, s *driver.Server, resources *DynamicResources, manualOps ...driver.SqlServerOpt) *driver.SqlServer {
366 if s == nil {
367 return nil
368 }
369 if s.Port != 0 {
370 t.Fatal("cannot specify s.Port on these tests; please use {{get_port ...}} and dynamic_port: to specify a dynamic port.")
371 }
372 if s.DynamicPort == "" {
373 t.Fatal("you must specify s.DynamicPort on these tests; please use {{get_port ...}} and dynamic_port: to specify a dynamic port.")
374 }
375 port := resources.GetOrAllocatePort(s.DynamicPort)
376
377 rawArgs := make([]string, len(s.Args))
378 for i := range rawArgs {
379 rawArgs[i] = resources.ApplyTemplate(s.Args[i])
380 }
381 args := prepareDoltgresServerArgs(t, cwd, s.Name, port, rawArgs)
382
383 opts := []driver.SqlServerOpt{
384 driver.WithArgs(args...),
385 driver.WithName(s.Name),
386 driver.WithLogWriter(newTestLogWriter(t)),
387 driver.WithPort(port),
388 }
389 if len(s.Envs) > 0 {
390 opts = append(opts, driver.WithEnvs(s.Envs...))
391 }
392 opts = append(opts, manualOps...)
393
394 var server *driver.SqlServer
395 var err error
396 if s.DebugPort != 0 {
397 server, err = driver.DebugSqlServer(dc, s.DebugPort, opts...)
398 } else {
399 server, err = driver.StartSqlServer(dc, opts...)
400 }
401
402 require.NoError(t, err)
403 if len(s.ErrorMatches) > 0 {
404 err := server.ErrorStop()
405 require.Error(t, err)
406 output := server.Output.String()
407 for _, a := range s.ErrorMatches {
408 require.Regexp(t, a, output)
409 }
410 return nil
411 } else {
412 t.Cleanup(func() {
413 // We use assert, not require here, since FailNow() in
414 // a Cleanup does not make sense.
415 err := server.GracefulStop()
416 if assert.NoError(t, err) {
417 output := server.Output.String()
418 for _, a := range s.LogMatches {
419 assert.Regexp(t, a, output)
420 }
421 for _, a := range s.LogNotMatches {
422 assert.NotRegexp(t, a, output)

Callers 5

StartServerFunction · 0.85
RunServerUntilEndOfTestFunction · 0.85
RunMethod · 0.85
startServerWithMetricsFunction · 0.85

Calls 15

ErrorStopMethod · 0.95
GracefulStopMethod · 0.95
WithArgsFunction · 0.92
WithNameFunction · 0.92
WithLogWriterFunction · 0.92
WithPortFunction · 0.92
WithEnvsFunction · 0.92
DebugSqlServerFunction · 0.92
StartSqlServerFunction · 0.92
newTestLogWriterFunction · 0.85
FatalMethod · 0.80

Tested by 4

StartServerFunction · 0.68
RunServerUntilEndOfTestFunction · 0.68
startServerWithMetricsFunction · 0.68