kubernetes/test/conformance/image/go-runner/cmd_test.go
Tom Wieczorek 4977189c1b
Fix ginkgo noColor deprecation warning
Ginkgo changed the noColor command line arg to be no-color and will
issue the following warning:

You're using deprecated Ginkgo functionality:
=============================================
  --noColor is deprecated, use --no-color instead

Fix this by changing all occurrences accordingly.
2023-06-09 09:34:05 +02:00

145 lines
4.2 KiB
Go

/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"os"
"reflect"
"testing"
)
func TestGetCmd(t *testing.T) {
testCases := []struct {
desc string
env Getenver
expectArgs []string
}{
{
desc: "Default",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
},
},
expectArgs: []string{
"ginkgobin",
"--focus=", "--skip=",
"--no-color=true", "--timeout=24h", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
},
}, {
desc: "Filling in defaults",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
focusEnvKey: "focus",
skipEnvKey: "skip",
providerEnvKey: "provider",
resultsDirEnvKey: "results",
kubeconfigEnvKey: "kubeconfig",
},
},
expectArgs: []string{
"ginkgobin",
"--focus=focus", "--skip=skip",
"--no-color=true", "--timeout=24h", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=provider", "--report-dir=results", "--kubeconfig=kubeconfig",
},
}, {
desc: "Parallel gets set and skips serial",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
parallelEnvKey: "true",
},
},
expectArgs: []string{
"ginkgobin", "--p",
"--focus=", "--skip=\\[Serial\\]",
"--no-color=true", "--timeout=24h", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
},
}, {
desc: "Arbitrary options before and after double dash split by space",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
extraArgsEnvKey: "--extra=1 --extra=2",
extraGinkgoArgsEnvKey: "--ginkgo1 --ginkgo2",
},
},
expectArgs: []string{
"ginkgobin", "--focus=", "--skip=",
"--no-color=true", "--ginkgo1", "--ginkgo2", "--timeout=24h",
"testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
"--extra=1", "--extra=2",
},
}, {
desc: "Arbitrary options can be split by other tokens",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
extraArgsEnvKey: "--extra=value with spaces:--extra=value with % anything!$$",
extraGinkgoArgsEnvKey: `--ginkgo='with "quotes" and ':--ginkgo2=true$(foo)`,
extraArgsSeparaterEnvKey: ":",
},
},
expectArgs: []string{
"ginkgobin", "--focus=", "--skip=",
"--no-color=true", `--ginkgo='with "quotes" and '`, "--ginkgo2=true$(foo)", "--timeout=24h",
"testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
"--extra=value with spaces", "--extra=value with % anything!$$",
},
}, {
desc: "Set Ginkgo timeout in env",
env: &explicitEnv{
vals: map[string]string{
ginkgoEnvKey: "ginkgobin",
testBinEnvKey: "testbin",
extraGinkgoArgsEnvKey: "--timeout=10h",
},
},
expectArgs: []string{
"ginkgobin", "--focus=", "--skip=",
"--no-color=true", "--timeout=10h", "testbin", "--",
"--disable-log-dump", "--repo-root=/kubernetes",
"--provider=", "--report-dir=", "--kubeconfig=",
},
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
c := getCmd(tc.env, os.Stdout)
if !reflect.DeepEqual(c.Args, tc.expectArgs) {
t.Errorf("Expected args %q but got %q", tc.expectArgs, c.Args)
}
})
}
}