k8s.io/kubernetes@v1.29.3/test/conformance/image/go-runner/cmd_test.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "os" 21 "reflect" 22 "testing" 23 ) 24 25 func TestGetCmd(t *testing.T) { 26 testCases := []struct { 27 desc string 28 env Getenver 29 expectArgs []string 30 }{ 31 { 32 desc: "Default", 33 env: &explicitEnv{ 34 vals: map[string]string{ 35 ginkgoEnvKey: "ginkgobin", 36 testBinEnvKey: "testbin", 37 }, 38 }, 39 expectArgs: []string{ 40 "ginkgobin", 41 "--focus=", "--skip=", 42 "--no-color=true", "--timeout=24h", "testbin", "--", 43 "--disable-log-dump", "--repo-root=/kubernetes", 44 "--provider=", "--report-dir=", "--kubeconfig=", 45 }, 46 }, { 47 desc: "Filling in defaults", 48 env: &explicitEnv{ 49 vals: map[string]string{ 50 ginkgoEnvKey: "ginkgobin", 51 testBinEnvKey: "testbin", 52 focusEnvKey: "focus", 53 skipEnvKey: "skip", 54 providerEnvKey: "provider", 55 resultsDirEnvKey: "results", 56 kubeconfigEnvKey: "kubeconfig", 57 }, 58 }, 59 expectArgs: []string{ 60 "ginkgobin", 61 "--focus=focus", "--skip=skip", 62 "--no-color=true", "--timeout=24h", "testbin", "--", 63 "--disable-log-dump", "--repo-root=/kubernetes", 64 "--provider=provider", "--report-dir=results", "--kubeconfig=kubeconfig", 65 }, 66 }, { 67 desc: "Parallel gets set and skips serial", 68 env: &explicitEnv{ 69 vals: map[string]string{ 70 ginkgoEnvKey: "ginkgobin", 71 testBinEnvKey: "testbin", 72 parallelEnvKey: "true", 73 }, 74 }, 75 expectArgs: []string{ 76 "ginkgobin", "--p", 77 "--focus=", "--skip=\\[Serial\\]", 78 "--no-color=true", "--timeout=24h", "testbin", "--", 79 "--disable-log-dump", "--repo-root=/kubernetes", 80 "--provider=", "--report-dir=", "--kubeconfig=", 81 }, 82 }, { 83 desc: "Arbitrary options before and after double dash split by space", 84 env: &explicitEnv{ 85 vals: map[string]string{ 86 ginkgoEnvKey: "ginkgobin", 87 testBinEnvKey: "testbin", 88 extraArgsEnvKey: "--extra=1 --extra=2", 89 extraGinkgoArgsEnvKey: "--ginkgo1 --ginkgo2", 90 }, 91 }, 92 expectArgs: []string{ 93 "ginkgobin", "--focus=", "--skip=", 94 "--no-color=true", "--ginkgo1", "--ginkgo2", "--timeout=24h", 95 "testbin", "--", 96 "--disable-log-dump", "--repo-root=/kubernetes", 97 "--provider=", "--report-dir=", "--kubeconfig=", 98 "--extra=1", "--extra=2", 99 }, 100 }, { 101 desc: "Arbitrary options can be split by other tokens", 102 env: &explicitEnv{ 103 vals: map[string]string{ 104 ginkgoEnvKey: "ginkgobin", 105 testBinEnvKey: "testbin", 106 extraArgsEnvKey: "--extra=value with spaces:--extra=value with % anything!$$", 107 extraGinkgoArgsEnvKey: `--ginkgo='with "quotes" and ':--ginkgo2=true$(foo)`, 108 extraArgsSeparaterEnvKey: ":", 109 }, 110 }, 111 expectArgs: []string{ 112 "ginkgobin", "--focus=", "--skip=", 113 "--no-color=true", `--ginkgo='with "quotes" and '`, "--ginkgo2=true$(foo)", "--timeout=24h", 114 "testbin", "--", 115 "--disable-log-dump", "--repo-root=/kubernetes", 116 "--provider=", "--report-dir=", "--kubeconfig=", 117 "--extra=value with spaces", "--extra=value with % anything!$$", 118 }, 119 }, { 120 desc: "Set Ginkgo timeout in env", 121 env: &explicitEnv{ 122 vals: map[string]string{ 123 ginkgoEnvKey: "ginkgobin", 124 testBinEnvKey: "testbin", 125 extraGinkgoArgsEnvKey: "--timeout=10h", 126 }, 127 }, 128 expectArgs: []string{ 129 "ginkgobin", "--focus=", "--skip=", 130 "--no-color=true", "--timeout=10h", "testbin", "--", 131 "--disable-log-dump", "--repo-root=/kubernetes", 132 "--provider=", "--report-dir=", "--kubeconfig=", 133 }, 134 }, 135 } 136 for _, tc := range testCases { 137 t.Run(tc.desc, func(t *testing.T) { 138 c := getCmd(tc.env, os.Stdout) 139 if !reflect.DeepEqual(c.Args, tc.expectArgs) { 140 t.Errorf("Expected args %q but got %q", tc.expectArgs, c.Args) 141 } 142 }) 143 } 144 }