github.com/GoogleContainerTools/skaffold@v1.39.18/examples/custom-tests/main_test.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 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 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License. 12 */ 13 14 package main 15 16 import ( 17 "fmt" 18 "testing" 19 ) 20 21 func TestMinIntBasic(tb *testing.T) { 22 fmt.Println("Running Basic test.") 23 min := MinInt(5, -5) 24 if min != -5 { 25 tb.Errorf("MinInt(5, -5) returned %d; expecting -5", min) 26 } 27 } 28 29 func TestMinIntTableDriven(tdt *testing.T) { 30 var tests = []struct { 31 x, y int 32 want int 33 }{ 34 {0, 0, 0}, 35 {1, 0, 0}, 36 {0, 1, 0}, 37 {0, -1, -1}, 38 {-1, 0, -1}, 39 {-2, -5, -5}, 40 {-5, -2, -5}, 41 } 42 43 fmt.Println("Running Table driven test.") 44 for _, t := range tests { 45 testname := fmt.Sprintf("TestMinInt(): %d,%d", t.x, t.y) 46 tdt.Run(testname, func(tdt *testing.T) { 47 min := MinInt(t.x, t.y) 48 if min != t.want { 49 tdt.Errorf("MinInt(%d, %d) returned %d; expecting %d", t.x, t.y, min, t.want) 50 } 51 }) 52 } 53 }