github.com/coreos/mantle@v0.13.0/harness/test.go (about) 1 // Copyright 2017 CoreOS, 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 harness 16 17 import ( 18 "fmt" 19 20 "github.com/coreos/mantle/lang/maps" 21 ) 22 23 // Test is a single test function. 24 type Test func(*H) 25 26 // Tests is a set of test functions that can be given to a Suite. 27 type Tests map[string]Test 28 29 // Add inserts the given Test into the set, initializing Tests if needed. 30 // If a test with the given name already exists Add will panic. 31 func (ts *Tests) Add(name string, test Test) { 32 if *ts == nil { 33 *ts = make(Tests) 34 } else if _, ok := (*ts)[name]; ok { 35 panic(fmt.Errorf("harness: duplicate test %q", name)) 36 } 37 (*ts)[name] = test 38 } 39 40 // List returns a sorted list of test names. 41 func (ts Tests) List() []string { 42 return maps.NaturalKeys(ts) 43 }