Пример #1
0
// Temporary proof-of-concept test that uses the testingshim to set up a test
// server from the sql package.
func TestPOC(t *testing.T) {
	defer leaktest.AfterTest(t)()

	s := testingshim.NewTestServer()
	if err := s.Start(); err != nil {
		t.Fatal(err)
	}
	defer s.Stop()

	kvClient := s.ClientDB().(*client.DB)
	err := kvClient.Put("testkey", "testval")
	if err != nil {
		t.Fatal(err)
	}
	kv, err := kvClient.Get("testkey")
	if err != nil {
		t.Fatal(err)
	}
	if kv.PrettyValue() != `"testval"` {
		t.Errorf(`Invalid Get result: %s, expected "testval"`, kv.PrettyValue())
	}
}
Пример #2
0
// SetupServerWithParams creates a test server with the given params and sets up
// a gosql DB connection.
func SetupServerWithParams(t *testing.T, params testingshim.TestServerParams) (
	server testingshim.TestServerInterface, goDB *gosql.DB, kvClient *client.DB, cleanupFn func(),
) {
	server = testingshim.NewTestServer(params)
	if err := server.Start(); err != nil {
		t.Fatal(err)
	}

	kvClient = server.KVClient().(*client.DB)
	url, cleanupGoDB := PGUrl(t, server.ServingAddr(), security.RootUser, "SetupServer")
	goDB, err := gosql.Open("postgres", url.String())
	if err != nil {
		t.Fatal(err)
	}

	cleanupFn = func() {
		_ = goDB.Close()
		cleanupGoDB()
		server.Stop()
	}
	return server, goDB, kvClient, cleanupFn
}