github.com/ecodeclub/eorm@v0.0.2-0.20231001112437-dae71da914d0/internal/dialect/dialect_test.go (about) 1 // Copyright 2021 ecodeclub 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package dialect 16 17 import ( 18 "testing" 19 20 "github.com/ecodeclub/eorm/internal/errs" 21 "github.com/stretchr/testify/assert" 22 ) 23 24 func TestOf(t *testing.T) { 25 testCases := []struct { 26 name string 27 driver string 28 wantErr error 29 wantDialect Dialect 30 }{ 31 { 32 name: "mysql", 33 driver: "mysql", 34 wantDialect: MySQL, 35 }, 36 { 37 name: "sqlite3", 38 driver: "sqlite3", 39 wantDialect: SQLite, 40 }, 41 { 42 name: "unsupported", 43 driver: "abc", 44 wantErr: errs.NewUnsupportedDriverError("abc"), 45 }, 46 } 47 48 for _, tc := range testCases { 49 t.Run(tc.name, func(t *testing.T) { 50 dialect, err := Of(tc.driver) 51 assert.Equal(t, tc.wantErr, err) 52 if err != nil { 53 return 54 } 55 assert.Equal(t, tc.wantDialect, dialect) 56 }) 57 } 58 }