github.com/sacloud/iaas-api-go@v1.12.0/testutil/testing.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go Authors 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 testutil 16 17 import ( 18 "os" 19 ) 20 21 // TestT テストのライフサイクルを管理するためのインターフェース. 22 // 23 // 通常は*testing.Tを実装として利用する 24 type TestT interface { 25 Log(args ...interface{}) 26 Logf(format string, args ...interface{}) 27 Error(args ...interface{}) 28 Errorf(format string, args ...interface{}) 29 FailNow() 30 Fatal(args ...interface{}) 31 Skip(args ...interface{}) 32 Skipf(format string, args ...interface{}) 33 Name() string 34 Parallel() 35 } 36 37 // PreCheckEnvsFunc 指定の環境変数が指定されていなかった場合にテストをスキップするためのFuncを返す 38 func PreCheckEnvsFunc(envs ...string) func(TestT) { 39 return func(t TestT) { 40 for _, env := range envs { 41 v := os.Getenv(env) 42 if v == "" { 43 t.Skipf("environment variable %q is not set. skip", env) 44 } 45 } 46 } 47 }