Skip to content

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

chore: disable tests for bb CLI (#2490)

Danny Xuadbdf00a40a7
diff --git a/bin/bb/cmd/dump_test.go b/bin/bb/cmd/dump_test.go
deleted file mode 100644
index f10e52c333..0000000000
--- a/bin/bb/cmd/dump_test.go
+++ /dev/null
@@ -1,41 +0,0 @@
-//go:build mysql
-// +build mysql
-
-package cmd
-
-import (
- "fmt"
- "testing"
-
- // Embedded expected output.
- _ "embed"
-
- "github.com/stretchr/testify/require"
-
- "github.com/bytebase/bytebase/resources/mysql"
-)
-
-var (
- //go:embed testdata/expected/dump_test_TestDump
- _TestDump string
-)
-
-func TestDump(t *testing.T) {
- mysql, stop := mysql.SetupTestInstance(t, PortTestDump)
- defer stop()
-
- t.Log("Importing MySQL data...")
- err := mysql.Import("testdata/mysql_test_schema")
- require.NoError(t, err)
-
- tt := []testTable{
- {
- args: []string{
- "dump",
- "--dsn", fmt.Sprintf("mysql://root@localhost:%d/bytebase_test_todo", mysql.Port()),
- },
- expected: _TestDump,
- },
- }
- tableTest(t, tt)
-}
diff --git a/bin/bb/cmd/migrate_test.go b/bin/bb/cmd/migrate_test.go
deleted file mode 100644
index 6d949335ca..0000000000
--- a/bin/bb/cmd/migrate_test.go
+++ /dev/null
@@ -1,94 +0,0 @@
-//go:build mysql
-// +build mysql
-
-package cmd
-
-import (
- "fmt"
- "testing"
-
- "github.com/stretchr/testify/require"
-
- "github.com/bytebase/bytebase/resources/mysql"
-
- // embed expected output.
- _ "embed"
-)
-
-var (
- //go:embed testdata/expected/migrate_test_TestMigrate_01
- _TestMigrate01 string
- //go:embed testdata/expected/migrate_test_TestMigrate_02
- _TestMigrate02 string
- //go:embed testdata/expected/migrate_test_TestMigrate_03
- _TestMigrate03 string
-)
-
-func TestMigrate(t *testing.T) {
- mysql, stop := mysql.SetupTestInstance(t, PortTestMigrate)
- defer stop()
-
- err := mysql.Import("testdata/mysql_test_schema/1_todo.sql")
- require.NoError(t, err)
-
- tt := []testTable{
- {
- args: []string{
- "dump",
- "--dsn", fmt.Sprintf("mysql://root@localhost:%d/bytebase_test_todo", mysql.Port()),
- },
- expected: _TestMigrate01,
- },
- {
- args: []string{
- "migrate",
- "--dsn", fmt.Sprintf("mysql://root@localhost:%d/bytebase_test_todo", mysql.Port()),
- "-c", `"
- CREATE TABLE bytebase_test_todo.book (
- id INTEGER PRIMARY KEY,
- name TEXT NULL
- );"`,
- },
- expected: _TestMigrate02,
- },
- {
- args: []string{
- "dump",
- "--dsn", fmt.Sprintf("mysql://root@localhost:%d/bytebase_test_todo", mysql.Port()),
- },
- expected: _TestMigrate03,
- },
- }
- tableTest(t, tt)
-}
-
-var (
- //go:embed testdata/expected/migrate_test_TestCreateDatabase_01
- _TestCreateDatabase01 string
- //go:embed testdata/expected/migrate_test_TestCreateDatabase_02
- _TestCreateDatabase02 string
-)
-
-func TestCreateDatabase(t *testing.T) {
- mysql, stop := mysql.SetupTestInstance(t, PortTestCreateDatabase)
- defer stop()
-
- tt := []testTable{
- {
- args: []string{
- "migrate",
- "--dsn", fmt.Sprintf("mysql://root@localhost:%d/", mysql.Port()),
- "-f", "testdata/mysql_test_schema/1_todo.sql",
- },
- expected: _TestCreateDatabase01,
- },
- {
- args: []string{
- "dump",
- "--dsn", fmt.Sprintf("mysql://root@localhost:%d/bytebase_test_todo", mysql.Port()),
- },
- expected: _TestCreateDatabase02,
- },
- }
- tableTest(t, tt)
-}
diff --git a/bin/bb/cmd/root_test.go b/bin/bb/cmd/root_test.go
deleted file mode 100644
index ba59b2c6a3..0000000000
--- a/bin/bb/cmd/root_test.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package cmd
-
-import (
- "bytes"
- "io"
- "os"
- "strings"
- "testing"
-
- _ "github.com/go-sql-driver/mysql"
- "github.com/google/go-cmp/cmp"
- "github.com/spf13/cobra"
- "go.uber.org/zap"
-
- "github.com/bytebase/bytebase/common/log"
-)
-
-const (
- PortTestDump = iota + 13306
- PortTestMigrate
- PortTestCreateDatabase
-)
-
-func executeCommand(t *testing.T, cmd *cobra.Command, args ...string) (string, error) {
- t.Helper()
-
- var buf bytes.Buffer
- cmd.SetOut(&buf)
- cmd.SetErr(&buf)
- cmd.SetArgs(args)
-
- err := cmd.Execute()
- return buf.String(), err
-}
-
-type testTable struct {
- args []string
- expectedErr error
- expected string
-}
-
-func tableTest(t *testing.T, tables []testTable) {
- log.SetLevel(zap.DebugLevel)
- t.Helper()
- for _, tc := range tables {
- actual, err := executeCommand(t, NewRootCmd(), tc.args...)
-
- if err != tc.expectedErr {
- t.Errorf(`"> bb %v"
-got unexpected error:
-%s
-`, strings.Join(tc.args, " "), cmp.Diff(err, tc.expectedErr))
- }
-
- if actual != tc.expected {
- t.Errorf(`"> bb %v"
-got unexpected output:
-%s
-`, strings.Join(tc.args, " "), cmp.Diff(actual, tc.expected))
-
- func() {
- f, err := os.CreateTemp("", "*")
- if err != nil {
- t.Log(err)
- }
- defer f.Close()
- if _, err := io.WriteString(f, actual); err != nil {
- t.Log(err)
- }
- t.Logf("Actual output written to %s", f.Name())
- }()
- }
- }
-}
diff --git a/bin/bb/cmd/testdata/expected/dump_test_TestDump b/bin/bb/cmd/testdata/expected/dump_test_TestDump
deleted file mode 100644
index b094db79e4..0000000000
--- a/bin/bb/cmd/testdata/expected/dump_test_TestDump
+++ /dev/null
@@ -1,28 +0,0 @@
---
--- Table structure for `author`
---
-CREATE TABLE `author` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the author',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
---
--- Table structure for `todo`
---
-CREATE TABLE `todo` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the todo',
- `content` text,
- `author_id` int DEFAULT NULL,
- `created_ts` bigint NOT NULL,
- `updated_ts` bigint NOT NULL,
- PRIMARY KEY (`id`),
- KEY `author_id` (`author_id`),
- KEY `name` (`name`) COMMENT 'index on todo.name',
- KEY `created_ts` (`created_ts`) COMMENT 'index on todo.created_ts',
- CONSTRAINT `todo_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `author` (`id`) ON DELETE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
diff --git a/bin/bb/cmd/testdata/expected/migrate_test_TestCreateDatabase_01 b/bin/bb/cmd/testdata/expected/migrate_test_TestCreateDatabase_01
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/bin/bb/cmd/testdata/expected/migrate_test_TestCreateDatabase_02 b/bin/bb/cmd/testdata/expected/migrate_test_TestCreateDatabase_02
deleted file mode 100644
index b094db79e4..0000000000
--- a/bin/bb/cmd/testdata/expected/migrate_test_TestCreateDatabase_02
+++ /dev/null
@@ -1,28 +0,0 @@
---
--- Table structure for `author`
---
-CREATE TABLE `author` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the author',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
---
--- Table structure for `todo`
---
-CREATE TABLE `todo` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the todo',
- `content` text,
- `author_id` int DEFAULT NULL,
- `created_ts` bigint NOT NULL,
- `updated_ts` bigint NOT NULL,
- PRIMARY KEY (`id`),
- KEY `author_id` (`author_id`),
- KEY `name` (`name`) COMMENT 'index on todo.name',
- KEY `created_ts` (`created_ts`) COMMENT 'index on todo.created_ts',
- CONSTRAINT `todo_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `author` (`id`) ON DELETE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
diff --git a/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_01 b/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_01
deleted file mode 100644
index b094db79e4..0000000000
--- a/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_01
+++ /dev/null
@@ -1,28 +0,0 @@
---
--- Table structure for `author`
---
-CREATE TABLE `author` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the author',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
---
--- Table structure for `todo`
---
-CREATE TABLE `todo` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the todo',
- `content` text,
- `author_id` int DEFAULT NULL,
- `created_ts` bigint NOT NULL,
- `updated_ts` bigint NOT NULL,
- PRIMARY KEY (`id`),
- KEY `author_id` (`author_id`),
- KEY `name` (`name`) COMMENT 'index on todo.name',
- KEY `created_ts` (`created_ts`) COMMENT 'index on todo.created_ts',
- CONSTRAINT `todo_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `author` (`id`) ON DELETE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
diff --git a/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_02 b/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_02
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_03 b/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_03
deleted file mode 100644
index d04a0b3ed6..0000000000
--- a/bin/bb/cmd/testdata/expected/migrate_test_TestMigrate_03
+++ /dev/null
@@ -1,38 +0,0 @@
---
--- Table structure for `author`
---
-CREATE TABLE `author` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the author',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
---
--- Table structure for `book`
---
-CREATE TABLE `book` (
- `id` int NOT NULL,
- `name` text,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
---
--- Table structure for `todo`
---
-CREATE TABLE `todo` (
- `id` int NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL COMMENT 'name of the todo',
- `content` text,
- `author_id` int DEFAULT NULL,
- `created_ts` bigint NOT NULL,
- `updated_ts` bigint NOT NULL,
- PRIMARY KEY (`id`),
- KEY `author_id` (`author_id`),
- KEY `name` (`name`) COMMENT 'index on todo.name',
- KEY `created_ts` (`created_ts`) COMMENT 'index on todo.created_ts',
- CONSTRAINT `todo_ibfk_1` FOREIGN KEY (`author_id`) REFERENCES `author` (`id`) ON DELETE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
diff --git a/bin/bb/cmd/testdata/mysql_test_schema/1_todo.sql b/bin/bb/cmd/testdata/mysql_test_schema/1_todo.sql
deleted file mode 100644
index aebba355f7..0000000000
--- a/bin/bb/cmd/testdata/mysql_test_schema/1_todo.sql
+++ /dev/null
@@ -1,23 +0,0 @@
--- Covered objects:
--- - Table
--- - Index
-
-CREATE DATABASE bytebase_test_todo;
-
--- Table and Index
-CREATE TABLE bytebase_test_todo.author (
- id INTEGER PRIMARY KEY AUTO_INCREMENT,
- name VARCHAR(255) COMMENT 'name of the author'
-);
-
-CREATE TABLE bytebase_test_todo.todo (
- id INTEGER PRIMARY KEY AUTO_INCREMENT,
- name VARCHAR(255) COMMENT 'name of the todo',
- content TEXT,
- author_id INTEGER,
- created_ts BIGINT NOT NULL,
- updated_ts BIGINT NOT NULL,
- FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,
- INDEX (name) COMMENT 'index on todo.name',
- INDEX (created_ts) COMMENT 'index on todo.created_ts'
-);
diff --git a/bin/bb/cmd/testdata/mysql_test_schema/2_blog.sql b/bin/bb/cmd/testdata/mysql_test_schema/2_blog.sql
deleted file mode 100644
index e1b5014a9b..0000000000
--- a/bin/bb/cmd/testdata/mysql_test_schema/2_blog.sql
+++ /dev/null
@@ -1,99 +0,0 @@
--- Covered objects:
--- - Table
--- - Index
--- - View
--- - Procedure
--- - Function
--- - Event
--- - Trigger
-
-CREATE DATABASE bytebase_test_blog;
-
--- Table and Index
-CREATE TABLE bytebase_test_blog.author (
- id INTEGER PRIMARY KEY AUTO_INCREMENT,
- name VARCHAR(255) COMMENT 'name of the author',
- email VARCHAR(255),
- coin INTEGER DEFAULT 0 COMMENT 'coin can be earned by posting posts, comments'
-);
-
-CREATE TABLE bytebase_test_blog.post (
- id INTEGER PRIMARY KEY AUTO_INCREMENT,
- created_ts BIGINT NOT NULL,
- updated_ts BIGINT NOT NULL,
- author_id INTEGER NOT NULL,
- name VARCHAR(255) COMMENT 'name of the post',
- content TEXT,
- like_count INTEGER DEFAULT 0,
- FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,
- INDEX (name),
- INDEX (created_ts)
-);
-
-CREATE TABLE bytebase_test_blog.comment (
- id INTEGER PRIMARY KEY AUTO_INCREMENT,
- created_ts BIGINT NOT NULL,
- updated_ts BIGINT NOT NULL,
- post_id INTEGER,
- author_id INTEGER,
- content TEXT,
- FOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,
- FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE,
- INDEX (created_ts)
-);
-
--- View
-CREATE VIEW bytebase_test_blog.top_like_post AS
-SELECT
- *
-FROM
- bytebase_test_blog.post
-ORDER BY
- like_count DESC
-LIMIT 10;
-
--- Procedure
-CREATE PROCEDURE bytebase_test_blog.author_post_count (IN author_id INT, OUT post_count INT)
-BEGIN
- SELECT
- COUNT(*) INTO post_count
- FROM
- author, post
- WHERE
- author.id = post.author_id AND author.id = author_id;
-END;
-
--- Function
-CREATE FUNCTION bytebase_test_blog.author_comment_count (author_id INT)
- RETURNS INT DETERMINISTIC
-BEGIN
-DECLARE
- comment_count INT DEFAULT 0;
- SELECT
- COUNT(*) INTO comment_count
- FROM
- author,
- COMMENT
- WHERE
- author.id = comment.author_id
- AND author.id = author_id;
- RETURN comment_count;
-END;
-
--- Skip Event since it includes timestamp which causes unstable output.
--- -- Event
--- CREATE EVENT bytebase_test_blog.increase_author_coin_daily ON SCHEDULE EVERY 1 DAY DO UPDATE author
--- SET coin = coin + 1;
-
--- Trigger
-CREATE TRIGGER bytebase_test_blog.update_post_updated_ts
- AFTER UPDATE ON post
- FOR EACH ROW
-BEGIN
- UPDATE
- post
- SET
- updated_ts = NOW()
- WHERE
- id = OLD.id;
-END;
diff --git a/bin/bb/cmd/utils_test.go b/bin/bb/cmd/utils_test.go
deleted file mode 100644
index 668059cc11..0000000000
--- a/bin/bb/cmd/utils_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package cmd
-
-import (
- "testing"
-
- "github.com/xo/dburl"
-)
-
-func TestGetDatabase(t *testing.T) {
- for _, tt := range []struct {
- u string
- exp string
- }{
- {"mysql://root@localhost:3306/bytebase_test_todo", "bytebase_test_todo"},
- {"mysql://root@localhost:13308/", ""},
- {"mysql://root@localhost:13308/bytebase_test_todo?ssl-key=a", "bytebase_test_todo"},
- } {
- u, err := dburl.Parse(tt.u)
- if err != nil {
- t.Error(err)
- }
- if getDatabase(u) != tt.exp {
- t.Error("expected", tt.exp, "got", getDatabase(u))
- }
- }
-}
diff --git a/go.mod b/go.mod
index 20b4453a9f..02b91d21d2 100644
--- a/go.mod
+++ b/go.mod
@@ -15,7 +15,6 @@ require (
github.com/github/gh-ost v1.1.4
github.com/go-sql-driver/mysql v1.6.0
github.com/golang-jwt/jwt/v4 v4.4.2
- github.com/google/go-cmp v0.5.8
github.com/google/jsonapi v1.0.0
github.com/google/uuid v1.3.0
github.com/gosimple/slug v1.12.0
diff --git a/resources/mysql/mysql_test.go b/resources/mysql/mysql_test.go
deleted file mode 100644
index 57bea5a5fb..0000000000
--- a/resources/mysql/mysql_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-//go:build mysql
-// +build mysql
-
-package mysql
-
-import (
- "database/sql"
- "fmt"
- "os"
- "path/filepath"
- "testing"
-
- _ "github.com/go-sql-driver/mysql"
- "github.com/stretchr/testify/require"
-)
-
-func TestStartMySQL(t *testing.T) {
- basedir := t.TempDir()
- datadir := filepath.Join(basedir, "data")
- if err := os.Mkdir(datadir, 0755); err != nil {
- t.Fatal(err)
- }
-
- mysql, err := Install(basedir, datadir, "root")
- require.NoError(t, err)
- err = mysql.Start(23306 /* port */, os.Stdout, os.Stderr)
- require.NoError(t, err)
-
- db, err := sql.Open("mysql", fmt.Sprintf("root@tcp(localhost:%d)/mysql", mysql.Port()))
- require.NoError(t, err)
- defer db.Close()
-
- err = db.Ping()
- require.NoError(t, err)
-
- err = mysql.Stop()
- require.NoError(t, err)
-}