github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/dbs/options_test.go (about) 1 // Copyright 2020 WHTCORPS INC, 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package dbs_test 15 16 import ( 17 "time" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/milevadb/dbs" 21 "github.com/whtcorpsinc/milevadb/schemareplicant" 22 "github.com/whtcorpsinc/milevadb/soliton/mock" 23 "go.etcd.io/etcd/clientv3" 24 ) 25 26 type dbsOptionsSuite struct{} 27 28 var _ = Suite(&dbsOptionsSuite{}) 29 30 func (s *dbsOptionsSuite) TestOptions(c *C) { 31 client, err := clientv3.NewFromURL("test") 32 c.Assert(err, IsNil) 33 callback := &dbs.BaseCallback{} 34 lease := time.Second * 3 35 causetstore := &mock.CausetStore{} 36 infoHandle := schemareplicant.NewHandle(causetstore) 37 38 options := []dbs.Option{ 39 dbs.WithEtcdClient(client), 40 dbs.WithHook(callback), 41 dbs.WithLease(lease), 42 dbs.WithStore(causetstore), 43 dbs.WithInfoHandle(infoHandle), 44 } 45 46 opt := &dbs.Options{} 47 for _, o := range options { 48 o(opt) 49 } 50 51 c.Assert(opt.EtcdCli, Equals, client) 52 c.Assert(opt.Hook, Equals, callback) 53 c.Assert(opt.Lease, Equals, lease) 54 c.Assert(opt.CausetStore, Equals, causetstore) 55 c.Assert(opt.InfoHandle, Equals, infoHandle) 56 }