github.com/turingchain2020/turingchain@v1.1.21/cmd/autotest/types/types.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package types 6 7 import "reflect" 8 9 //var 10 var ( 11 CliCmd string //turingchain cli可执行文件名 12 CheckTimeout int //用例check时超时次数 13 autoTestItems = make(map[string]AutoTest) //保存注册的dapp测试类型 14 ) 15 16 //AutoTest dapp实现auto test的接口,需要提供每个dapp对应的测试配置类型,并注册 17 type AutoTest interface { 18 GetName() string 19 GetTestConfigType() reflect.Type 20 } 21 22 //Init 超时次数等于总超时时间除以每次check时睡眠时间 23 func Init(cliCmd string, checkTimeout int) { 24 25 CliCmd = cliCmd 26 CheckTimeout = checkTimeout 27 } 28 29 //RegisterAutoTest 注册测试配置类型 30 func RegisterAutoTest(at AutoTest) { 31 32 if at == nil || len(at.GetName()) == 0 { 33 return 34 } 35 dapp := at.GetName() 36 37 if _, ok := autoTestItems[dapp]; ok { 38 panic("Register Duplicate Dapp, name = " + dapp) 39 } 40 autoTestItems[dapp] = at 41 } 42 43 //GetAutoTestConfig 获取测试配置类型 44 func GetAutoTestConfig(dapp string) reflect.Type { 45 46 if len(dapp) == 0 { 47 48 return nil 49 } 50 51 if config, ok := autoTestItems[dapp]; ok { 52 53 return config.GetTestConfigType() 54 } 55 56 return nil 57 }