github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/api_test.go (about) 1 /* 2 * Copyright 2018 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. 3 */ 4 5 // IMPORTANT: DO NOT ADD build tags to this file 6 7 package govcd 8 9 import ( 10 "fmt" 11 "os" 12 "testing" 13 ) 14 15 var testingTags = make(map[string]string) 16 17 var testVerbose bool = os.Getenv("GOVCD_TEST_VERBOSE") != "" 18 19 // longer than the 128 characters so nothing can be named this 20 var INVALID_NAME = `*******************************************INVALID 21 **************************************************** 22 ************************` 23 24 // This ID won't be found by lookup in any entity 25 var invalidEntityId = "urn:vcloud:three:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" 26 27 func tagsHelp(t *testing.T) { 28 29 var helpText string = ` 30 # ----------------------------------------------------- 31 # Tags are required to run the tests 32 # ----------------------------------------------------- 33 34 At least one of the following tags should be defined: 35 36 * ALL : Runs all the tests (== functional + unit == all feature tests) 37 38 * functional: Runs all the tests that use check.v1 39 * unit: Runs unit tests that do not use check.v1 and don't need a live vCD 40 41 * catalog: Runs catalog related tests (also catalog_item, media) 42 * disk: Runs disk related tests 43 * extnetwork: Runs external network related tests 44 * lb: Runs load balancer related tests 45 * network: Runs network related tests 46 * gateway: Runs edge gateway related tests 47 * org: Runs org related tests 48 * query: Runs query related tests 49 * system: Runs system related tests 50 * task: Runs task related tests 51 * user: Runs user related tests 52 * vapp: Runs vapp related tests 53 * vdc: Runs vdc related tests 54 * vdcGroup: Runs vdc group related tests 55 * certificate Runs certificate related tests 56 * vm: Runs vm related tests 57 58 Examples: 59 60 go test -tags functional -check.vv -timeout=45m . 61 go test -tags catalog -check.vv -timeout=15m . 62 go test -tags "query extension" -check.vv -timeout=5m . 63 go test -tags functional -check.vv -check.f Test_AddNewVM -timeout=15m . 64 go test -v -tags unit . 65 ` 66 t.Logf(helpText) 67 } 68 69 // Tells indirectly if a tag has been set 70 // For every tag there is an `init` function that 71 // fills an item in `testingTags` 72 func isTagSet(tagName string) bool { 73 _, ok := testingTags[tagName] 74 return ok 75 } 76 77 // For troubleshooting: 78 // Shows which tags were set, and in which file. 79 func showTags() { 80 if len(testingTags) > 0 { 81 fmt.Println("# Defined tags:") 82 } 83 for k, v := range testingTags { 84 fmt.Printf("# %s (%s)", k, v) 85 } 86 } 87 88 // Checks whether any tags were defined, and raises an error if not 89 func TestTags(t *testing.T) { 90 if len(testingTags) == 0 { 91 t.Logf("# No tags were defined") 92 tagsHelp(t) 93 t.Fail() 94 return 95 } 96 if os.Getenv("SHOW_TAGS") != "" { 97 showTags() 98 } 99 } 100 101 func printVerbose(format string, args ...interface{}) { 102 if testVerbose { 103 fmt.Printf(format, args...) 104 } 105 } 106 107 func logVerbose(t *testing.T, format string, args ...interface{}) { 108 if testVerbose { 109 t.Logf(format, args...) 110 } 111 }