Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use testify assertion for testing (#876)

Danny Xu3da51e79518b
diff --git a/go.mod b/go.mod
index 814f59d591..1abfa288fc 100644
--- a/go.mod
+++ b/go.mod
@@ -22,6 +22,7 @@ require (
github.com/qiangmzsx/string-adapter/v2 v2.1.0
github.com/snowflakedb/gosnowflake v1.6.3
github.com/spf13/cobra v1.2.0
+ github.com/stretchr/testify v1.7.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
go.uber.org/zap v1.19.1
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
diff --git a/tests/start_test.go b/tests/start_test.go
index ed4e6c98e8..e5a15de1a4 100644
--- a/tests/start_test.go
+++ b/tests/start_test.go
@@ -2,49 +2,37 @@ package tests
import (
"context"
- "fmt"
"testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestServiceRestart(t *testing.T) {
t.Parallel()
- err := func() error {
- ctx := context.Background()
- ctl := &controller{}
- dataDir := t.TempDir()
- if err := ctl.StartMain(ctx, dataDir, getTestPort(t.Name())); err != nil {
- return err
- }
-
- if err := ctl.Login(); err != nil {
- return err
- }
-
- projects, err := ctl.getProjects()
- if err != nil {
- return err
- }
- // Test seed should have more than one project.
- if len(projects) <= 1 {
- return fmt.Errorf("unexpected number of projects %v", len(projects))
- }
-
- // Restart the server.
- if err := ctl.Close(); err != nil {
- return err
- }
-
- if err := ctl.StartMain(ctx, dataDir, getTestPort(t.Name())); err != nil {
- return err
- }
- defer ctl.Close()
-
- if err := ctl.Login(); err != nil {
- return err
- }
- return nil
- }()
- if err != nil {
- t.Error(err)
- }
+ ctx := context.Background()
+ ctl := &controller{}
+ dataDir := t.TempDir()
+ err := ctl.StartMain(ctx, dataDir, getTestPort(t.Name()))
+ require.NoError(t, err)
+
+ err = ctl.Login()
+ require.NoError(t, err)
+
+ projects, err := ctl.getProjects()
+ require.NoError(t, err)
+
+ // Test seed should have more than one project.
+ assert.Greater(t, len(projects), 1)
+
+ // Restart the server.
+ err = ctl.Close()
+ require.NoError(t, err)
+
+ err = ctl.StartMain(ctx, dataDir, getTestPort(t.Name()))
+ require.NoError(t, err)
+ defer ctl.Close()
+
+ err = ctl.Login()
+ require.NoError(t, err)
}