github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/pgwire/pgtest_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package pgwire
    12  
    13  import (
    14  	"context"
    15  	"flag"
    16  	"testing"
    17  
    18  	"github.com/cockroachdb/cockroach/pkg/base"
    19  	"github.com/cockroachdb/cockroach/pkg/security"
    20  	"github.com/cockroachdb/cockroach/pkg/testutils/pgtest"
    21  	"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
    22  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    23  )
    24  
    25  var (
    26  	flagAddr = flag.String("addr", "", "pass a custom postgres address to TestWalk instead of starting an in-memory node")
    27  	flagUser = flag.String("user", "postgres", "username used if -addr is specified")
    28  )
    29  
    30  func TestPGTest(t *testing.T) {
    31  	defer leaktest.AfterTest(t)()
    32  
    33  	if *flagAddr == "" {
    34  		newServer := func() (addr, user string, cleanup func()) {
    35  			ctx := context.Background()
    36  			s, _, _ := serverutils.StartServer(t, base.TestServerArgs{
    37  				Insecure: true,
    38  			})
    39  			cleanup = func() {
    40  				s.Stopper().Stop(ctx)
    41  			}
    42  			addr = s.ServingSQLAddr()
    43  			user = security.RootUser
    44  			return addr, user, cleanup
    45  		}
    46  		pgtest.WalkWithNewServer(t, "testdata/pgtest", newServer)
    47  	} else {
    48  		pgtest.WalkWithRunningServer(t, "testdata/pgtest", *flagAddr, *flagUser)
    49  	}
    50  }