vitess.io/vitess@v0.16.2/go/vt/vtadmin/vtsql/fakevtsql/doc.go (about) 1 /* 2 Copyright 2020 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package fakevtsql provides an interface for mocking out sql.DB responses in 18 // tests that depend on a vtsql.DB instance. 19 // 20 // To use fakevtsql, you will need to create a discovery implementation that 21 // does not error, e.g. with fakediscovery: 22 // 23 // disco := fakediscovery.New() 24 // disco.AddTaggedGates(nil, []*vtadminpb.VTGate{Hostname: "gate"}) 25 // 26 // Then, you will call vtsql.New(), passing the faked discovery implementation 27 // into the config: 28 // 29 // db := vtsql.New(&vtsql.Config{ 30 // Cluster: &vtadminpb.Cluster{Id: "cid", Name: "cluster"}, 31 // Discovery: disco, 32 // }) 33 // 34 // Finally, with your instantiated VTGateProxy instance, you can mock out the 35 // DialFunc to always return a fakevtsql.Connector. The Tablets and ShouldErr 36 // attributes of the connector control the behavior: 37 // 38 // db.DialFunc = func(cfg vitessdriver.Configuration) (*sql.DB, error) { 39 // return sql.OpenDB(&fakevtsql.Connector{ 40 // Tablets: mockTablets, 41 // ShouldErr: shouldErr, 42 // }) 43 // } 44 // cluster := &cluster.Cluster{ 45 // /* other attributes */ 46 // DB: db, 47 // } 48 // 49 // go/vt/vtadmin/api_test.go has several examples of usage. 50 package fakevtsql