github.com/erda-project/erda-infra@v1.0.9/providers/mysqlxorm/xorm_test.go (about) 1 // Copyright (c) 2021 Terminus, Inc. 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 mysqlxorm 16 17 import ( 18 "testing" 19 "time" 20 ) 21 22 func Test_config_url(t *testing.T) { 23 type fields struct { 24 MySQLURL string 25 MySQLHost string 26 MySQLPort string 27 MySQLUsername string 28 MySQLPassword string 29 MySQLDatabase string 30 MySQLMaxIdleConns uint64 31 MySQLMaxOpenConns uint64 32 MySQLMaxLifeTime time.Duration 33 MySQLShowSQL bool 34 MySQLProperties string 35 MySQLTLS string 36 MySQLPingWhenInit bool 37 MySQLPingTimeoutSec uint64 38 } 39 tests := []struct { 40 name string 41 fields fields 42 want string 43 }{ 44 { 45 name: "test_not_have_tls", 46 fields: fields{ 47 MySQLUsername: "erda", 48 MySQLHost: "erda", 49 MySQLProperties: "erda", 50 MySQLDatabase: "erda", 51 MySQLPort: "3306", 52 MySQLPassword: "erda", 53 }, 54 want: "erda:erda@tcp(erda:3306)/erda?erda", 55 }, 56 { 57 name: "test_not_have_tls", 58 fields: fields{ 59 MySQLUsername: "erda", 60 MySQLHost: "erda", 61 MySQLProperties: "erda", 62 MySQLDatabase: "erda", 63 MySQLPort: "3306", 64 MySQLPassword: "erda", 65 MySQLTLS: "custom", 66 }, 67 want: "erda:erda@tcp(erda:3306)/erda?erda&tls=custom", 68 }, 69 } 70 for _, tt := range tests { 71 t.Run(tt.name, func(t *testing.T) { 72 c := &config{ 73 MySQLURL: tt.fields.MySQLURL, 74 MySQLHost: tt.fields.MySQLHost, 75 MySQLPort: tt.fields.MySQLPort, 76 MySQLUsername: tt.fields.MySQLUsername, 77 MySQLPassword: tt.fields.MySQLPassword, 78 MySQLDatabase: tt.fields.MySQLDatabase, 79 MySQLMaxIdleConns: tt.fields.MySQLMaxIdleConns, 80 MySQLMaxOpenConns: tt.fields.MySQLMaxOpenConns, 81 MySQLMaxLifeTime: tt.fields.MySQLMaxLifeTime, 82 MySQLShowSQL: tt.fields.MySQLShowSQL, 83 MySQLProperties: tt.fields.MySQLProperties, 84 MySQLTLS: tt.fields.MySQLTLS, 85 MySQLPingWhenInit: tt.fields.MySQLPingWhenInit, 86 MySQLPingTimeoutSec: tt.fields.MySQLPingTimeoutSec, 87 } 88 if got := c.url(); got != tt.want { 89 t.Errorf("url() = %v, want %v", got, tt.want) 90 } 91 }) 92 } 93 }