diff --git a/internal/database/dialect/mariadb_test.go b/internal/database/dialect/mariadb_test.go index b046eb47..aa912591 100644 --- a/internal/database/dialect/mariadb_test.go +++ b/internal/database/dialect/mariadb_test.go @@ -12,70 +12,6 @@ import ( v1 "k8s.io/api/core/v1" ) -func TestMariaDB_AnalyzeQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", ""}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.AnalyzeQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMariaDB_DatabaseEnvNames(t *testing.T) { - tests := []struct { - name string - want []string - }{ - {"default", []string{"MARIADB_DATABASE"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.DatabaseEnvNames() - assert.Equal(t, got, tt.want) - }) - } -} - -func TestMariaDB_DefaultPort(t *testing.T) { - tests := []struct { - name string - want uint16 - }{ - {"default", 3306}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.DefaultPort() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMariaDB_DefaultUser(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "root"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.DefaultUser() - assert.Equal(t, tt.want, got) - }) - } -} - func TestMariaDB_DropDatabaseQuery(t *testing.T) { type args struct { database string @@ -213,38 +149,6 @@ func TestMariaDB_ListDatabasesQuery(t *testing.T) { } } -func TestMariaDB_ListTablesQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "show tables"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.ListTablesQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMariaDB_Name(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "mariadb"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.Name() - assert.Equal(t, tt.want, got) - }) - } -} - func TestMariaDB_PasswordEnvNames(t *testing.T) { type args struct { c config.Global @@ -254,8 +158,8 @@ func TestMariaDB_PasswordEnvNames(t *testing.T) { args args want []string }{ - {"default", args{}, []string{"MARIADB_PASSWORD"}}, - {"root", args{config.Global{Username: "root"}}, []string{"MARIADB_ROOT_PASSWORD"}}, + {"default", args{}, []string{"MARIADB_PASSWORD", "MYSQL_PASSWORD"}}, + {"root", args{config.Global{Username: "root"}}, []string{"MARIADB_ROOT_PASSWORD", "MYSQL_ROOT_PASSWORD"}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -266,28 +170,6 @@ func TestMariaDB_PasswordEnvNames(t *testing.T) { } } -func TestMariaDB_PodLabels(t *testing.T) { - tests := []struct { - name string - want []kubernetes.LabelQueryable - }{ - {"default", []kubernetes.LabelQueryable{ - kubernetes.LabelQueryAnd{ - {Name: "app.kubernetes.io/name", Value: "mariadb"}, - {Name: "app.kubernetes.io/component", Value: "primary"}, - }, - kubernetes.LabelQuery{Name: "app", Value: "mariadb"}, - }}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.PodLabels() - assert.Equal(t, got, tt.want) - }) - } -} - func TestMariaDB_RestoreCommand(t *testing.T) { type args struct { conf config.Restore @@ -323,22 +205,6 @@ func TestMariaDB_RestoreCommand(t *testing.T) { } } -func TestMariaDB_UserEnvNames(t *testing.T) { - tests := []struct { - name string - want []string - }{ - {"default", []string{"MARIADB_USER"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MariaDB{} - got := ma.UserEnvNames() - assert.Equal(t, got, tt.want) - }) - } -} - func TestMariaDB_DumpExtension(t *testing.T) { type args struct { format sqlformat.Format diff --git a/internal/database/dialect/mongodb_test.go b/internal/database/dialect/mongodb_test.go index a8074df2..b74fc09a 100644 --- a/internal/database/dialect/mongodb_test.go +++ b/internal/database/dialect/mongodb_test.go @@ -12,90 +12,6 @@ import ( v1 "k8s.io/api/core/v1" ) -func TestMongoDB_AnalyzeQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", ""}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.AnalyzeQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMongoDB_DatabaseEnvNames(t *testing.T) { - tests := []struct { - name string - want []string - }{ - {"default", []string{"MONGODB_EXTRA_DATABASES"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.DatabaseEnvNames() - assert.Equal(t, got, tt.want) - }) - } -} - -func TestMongoDB_DefaultPort(t *testing.T) { - tests := []struct { - name string - want uint16 - }{ - {"default", 27017}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.DefaultPort() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMongoDB_DefaultUser(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "root"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.DefaultUser() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMongoDB_DropDatabaseQuery(t *testing.T) { - type args struct { - database string - } - tests := []struct { - name string - args args - want string - }{ - {"database", args{"database"}, ""}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.DropDatabaseQuery(tt.args.database) - assert.Equal(t, tt.want, got) - }) - } -} - func TestMongoDB_DumpCommand(t *testing.T) { type args struct { conf config.Dump @@ -202,54 +118,6 @@ func TestMongoDB_FilterPods(t *testing.T) { } } -func TestMongoDB_ListDatabasesQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "db.getMongo().getDBNames().forEach(function(db){ print(db) })"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.ListDatabasesQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMongoDB_ListTablesQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "show collections"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.ListTablesQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestMongoDB_Name(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "mongodb"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.Name() - assert.Equal(t, tt.want, got) - }) - } -} - func TestMongoDB_PasswordEnvNames(t *testing.T) { type args struct { c config.Global @@ -260,7 +128,7 @@ func TestMongoDB_PasswordEnvNames(t *testing.T) { want []string }{ {"default", args{}, []string{"MONGODB_EXTRA_PASSWORDS"}}, - {"root", args{config.Global{Host: "1.1.1.1", Username: "root"}}, []string{"MONGODB_ROOT_PASSWORD"}}, + {"root", args{config.Global{Username: "root"}}, []string{"MONGODB_ROOT_PASSWORD"}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -271,28 +139,6 @@ func TestMongoDB_PasswordEnvNames(t *testing.T) { } } -func TestMongoDB_PodLabels(t *testing.T) { - tests := []struct { - name string - want []kubernetes.LabelQueryable - }{ - {"default", []kubernetes.LabelQueryable{ - kubernetes.LabelQueryAnd{ - {Name: "app.kubernetes.io/name", Value: "mongodb"}, - {Name: "app.kubernetes.io/component", Value: "mongodb"}, - }, - kubernetes.LabelQuery{Name: "app", Value: "mongodb"}, - }}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.PodLabels() - assert.Equal(t, got, tt.want) - }) - } -} - func TestMongoDB_RestoreCommand(t *testing.T) { type args struct { conf config.Restore @@ -338,22 +184,6 @@ func TestMongoDB_RestoreCommand(t *testing.T) { } } -func TestMongoDB_UserEnvNames(t *testing.T) { - tests := []struct { - name string - want []string - }{ - {"default", []string{"MONGODB_EXTRA_USERNAMES", "MONGODB_ROOT_USER"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ma := MongoDB{} - got := ma.UserEnvNames() - assert.Equal(t, got, tt.want) - }) - } -} - func TestMongoDB_DumpExtension(t *testing.T) { type args struct { format sqlformat.Format diff --git a/internal/database/dialect/postgres_test.go b/internal/database/dialect/postgres_test.go index e355ec97..b052dded 100644 --- a/internal/database/dialect/postgres_test.go +++ b/internal/database/dialect/postgres_test.go @@ -13,90 +13,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func TestPostgres_AnalyzeQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "analyze;"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.AnalyzeQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestPostgres_DatabaseEnvNames(t *testing.T) { - tests := []struct { - name string - want []string - }{ - {"default", []string{"POSTGRES_DATABASE", "POSTGRES_DB"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.DatabaseEnvNames() - assert.Equal(t, got, tt.want) - }) - } -} - -func TestPostgres_DefaultPort(t *testing.T) { - tests := []struct { - name string - want uint16 - }{ - {"default", 5432}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.DefaultPort() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestPostgres_DefaultUser(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "postgres"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.DefaultUser() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestPostgres_DropDatabaseQuery(t *testing.T) { - type args struct { - database string - } - tests := []struct { - name string - args args - want string - }{ - {"default", args{"database"}, "drop schema public cascade; create schema public;"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.DropDatabaseQuery(tt.args.database) - assert.Equal(t, tt.want, got) - }) - } -} - func TestPostgres_DumpCommand(t *testing.T) { type args struct { conf config.Dump @@ -251,54 +167,6 @@ func TestPostgres_FilterPods(t *testing.T) { } } -func TestPostgres_ListDatabasesQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "SELECT datname FROM pg_database WHERE datistemplate = false"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.ListDatabasesQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestPostgres_ListTablesQuery(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.ListTablesQuery() - assert.Equal(t, tt.want, got) - }) - } -} - -func TestPostgres_Name(t *testing.T) { - tests := []struct { - name string - want string - }{ - {"default", "postgres"}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.Name() - assert.Equal(t, tt.want, got) - }) - } -} - func TestPostgres_PasswordEnvNames(t *testing.T) { type args struct { c config.Global @@ -309,7 +177,7 @@ func TestPostgres_PasswordEnvNames(t *testing.T) { want []string }{ {"default", args{}, []string{"POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD"}}, - {"postgres", args{config.Global{Host: "1.1.1.1", Username: "postgres"}}, []string{"POSTGRES_POSTGRES_PASSWORD", "POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD"}}, + {"postgres", args{config.Global{Username: "postgres"}}, []string{"POSTGRES_POSTGRES_PASSWORD", "POSTGRES_PASSWORD", "PGPOOL_POSTGRES_PASSWORD"}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -320,32 +188,6 @@ func TestPostgres_PasswordEnvNames(t *testing.T) { } } -func TestPostgres_PodLabels(t *testing.T) { - tests := []struct { - name string - want []kubernetes.LabelQueryable - }{ - {"default", []kubernetes.LabelQueryable{ - kubernetes.LabelQueryAnd{ - {Name: "app.kubernetes.io/name", Value: "postgresql"}, - {Name: "app.kubernetes.io/component", Value: "primary"}, - }, - kubernetes.LabelQueryAnd{ - {Name: "app.kubernetes.io/name", Value: "postgresql-ha"}, - {Name: "app.kubernetes.io/component", Value: "postgresql"}, - }, - kubernetes.LabelQuery{Name: "app", Value: "postgresql"}, - }}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.PodLabels() - assert.Equal(t, got, tt.want) - }) - } -} - func TestPostgres_RestoreCommand(t *testing.T) { pgpassword := command.NewEnv("PGPASSWORD", "") @@ -398,22 +240,6 @@ func TestPostgres_RestoreCommand(t *testing.T) { } } -func TestPostgres_UserEnvNames(t *testing.T) { - tests := []struct { - name string - want []string - }{ - {"default", []string{"POSTGRES_USER", "PGPOOL_POSTGRES_USERNAME"}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - po := Postgres{} - got := po.UserEnvNames() - assert.Equal(t, got, tt.want) - }) - } -} - func Test_quoteParam(t *testing.T) { type args struct { param string