Skip to content

Commit

Permalink
tests, flag: Parse flags once
Browse files Browse the repository at this point in the history
Current command line flags are setup at `init` but parsed multiple
times by each test file.

As the flags are bound to global variables and flag parsing should only
be executed once (consequent calls are no-op), there is no point to execute
the parse more than once.
The test framework is expected to execute the parsing in its main
function for its own flags, therefore, there should be no need to
explicitly parse the flags in the tests.

Signed-off-by: Edward Haas <[email protected]>
  • Loading branch information
EdDev committed Jul 16, 2020
1 parent d921fc6 commit 6ea6468
Show file tree
Hide file tree
Showing 44 changed files with 3 additions and 89 deletions.
2 changes: 0 additions & 2 deletions tests/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import (

var _ = Describe("[rfe_id:500][crit:high][vendor:[email protected]][level:component]User Access", func() {

tests.FlagParse()

view := tests.ViewServiceAccountName
edit := tests.EditServiceAccountName
admin := tests.AdminServiceAccountName
Expand Down
1 change: 0 additions & 1 deletion tests/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

var _ = Describe("[rfe_id:899][crit:medium][vendor:[email protected]][level:component]Config", func() {

tests.FlagParse()
var virtClient kubecli.KubevirtClient

BeforeEach(func() {
Expand Down
2 changes: 0 additions & 2 deletions tests/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ import (

var _ = Describe("[rfe_id:127][posneg:negative][crit:medium][vendor:[email protected]][level:component]Console", func() {

tests.FlagParse()
var virtClient kubecli.KubevirtClient


BeforeEach(func() {
var err error

Expand Down
2 changes: 0 additions & 2 deletions tests/container_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import (

var _ = Describe("[rfe_id:588][crit:medium][vendor:[email protected]][level:component]ContainerDisk", func() {

tests.FlagParse()

var virtClient kubecli.KubevirtClient
var err error

Expand Down
2 changes: 0 additions & 2 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const InvalidDataVolumeUrl = "http://127.0.0.1/invalid"
const DummyFilePath = "/usr/share/nginx/html/dummy.file"

var _ = Describe("DataVolume Integration", func() {
tests.FlagParse()


var virtClient kubecli.KubevirtClient
var err error
Expand Down
2 changes: 0 additions & 2 deletions tests/expose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func waitForJobToCompleteWithStatus(virtClient *kubecli.KubevirtClient, jobPod *

var _ = Describe("[rfe_id:253][crit:medium][vendor:[email protected]][level:component]Expose", func() {

tests.FlagParse()

var virtClient kubecli.KubevirtClient
var err error

Expand Down
2 changes: 0 additions & 2 deletions tests/imageupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const (

var _ = Describe("ImageUpload", func() {

tests.FlagParse()

namespace := tests.NamespaceTestDefault
dvName := "alpine-dv"
pvcSize := "100Mi"
Expand Down
2 changes: 0 additions & 2 deletions tests/infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import (
)

var _ = Describe("Infrastructure", func() {
tests.FlagParse()

var virtClient kubecli.KubevirtClient
var aggregatorClient *aggregatorclient.Clientset
var err error
Expand Down
2 changes: 0 additions & 2 deletions tests/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
)

var _ = Describe("[rfe_id:3423][vendor:[email protected]][level:component]oc/kubectl get vm/vmi tests", func() {
tests.FlagParse()

var k8sClient, result string
var vm *v1.VirtualMachine
var virtCli kubecli.KubevirtClient
Expand Down
1 change: 0 additions & 1 deletion tests/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const (
)

var _ = Describe("[rfe_id:393][crit:high][vendor:[email protected]][level:system] VM Live Migration", func() {
tests.FlagParse()
var virtClient kubecli.KubevirtClient

var originalKubeVirtConfig *k8sv1.ConfigMap
Expand Down
2 changes: 0 additions & 2 deletions tests/networkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func assertPingFail(ip string, vmi *v1.VirtualMachineInstance) {

var _ = Describe("[rfe_id:150][crit:high][vendor:[email protected]][level:component]Networkpolicy", func() {

tests.FlagParse()

var virtClient kubecli.KubevirtClient

var vmia *v1.VirtualMachineInstance
Expand Down
1 change: 0 additions & 1 deletion tests/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ type vmYamlDefinition struct {
}

var _ = Describe("Operator", func() {
tests.FlagParse()
var originalKv *v1.KubeVirt
var originalCDI *cdiv1.CDI
var originalKubeVirtConfig *k8sv1.ConfigMap
Expand Down
2 changes: 0 additions & 2 deletions tests/pausing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ import (

var _ = Describe("[rfe_id:3064][crit:medium][vendor:[email protected]][level:component]Pausing", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/probes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
)

var _ = Describe("[ref_id:1182]Probes", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/replicaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ var _ = Describe("[rfe_id:588][crit:medium][vendor:[email protected]][level:comp
var err error
var virtClient kubecli.KubevirtClient

tests.FlagParse()

BeforeEach(func() {
virtClient, err = kubecli.GetKubevirtClient()
tests.PanicOnError(err)
Expand Down
2 changes: 0 additions & 2 deletions tests/security_features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (
)

var _ = Describe("SecurityFeatures", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (

var _ = Describe("VirtualMachineSnapshot Tests", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/stability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

var _ = PDescribe("Ensure stable functionality", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const (
type VMICreationFunc func(string) *v1.VirtualMachineInstance

var _ = Describe("Storage", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/subresource_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ import (

var _ = Describe("Subresource Api", func() {

tests.FlagParse()

var err error
var virtCli kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const (
)

var _ = Describe("Templates", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
6 changes: 3 additions & 3 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ func init() {
flag.BoolVar(&SkipShasumCheck, "skip-shasums-check", false, "Skip tests with sha sums.")
}

func FlagParse() {
flag.Parse()

func NormalizeFlags() {
// When the flags are not provided, copy the values from normal version tag and prefix
if KubeVirtUtilityVersionTag == "" {
KubeVirtUtilityVersionTag = KubeVirtVersionTag
Expand Down Expand Up @@ -748,6 +746,8 @@ func Taint(nodeName string, key string, effect k8sv1.TaintEffect) {
}

func BeforeTestSuitSetup() {
NormalizeFlags()

log.InitializeLogging("tests")
log.Log.SetIOWriter(GinkgoWriter)

Expand Down
2 changes: 0 additions & 2 deletions tests/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (

var _ = Describe("Version", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/virt_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ var _ = Describe("[ref_id:2717]KubeVirt control plane resilience", func() {
var nodeNames []string
var selectedNodeName string

tests.FlagParse()

getRunningReadyPods := func(podList *v1.PodList, podNames []string, nodeNames ...string) (pods []*v1.Pod) {
pods = make([]*v1.Pod, 0)
for _, pod := range podList.Items {
Expand Down
2 changes: 0 additions & 2 deletions tests/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ import (

var _ = Describe("[rfe_id:1177][crit:medium][vendor:[email protected]][level:component]VirtualMachine", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vm_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ func createCommandWithNSAndRedirect(namespace, cmdName string, args ...string) (
}

var _ = Describe("[rfe_id:3423][crit:high][vendor:[email protected]][level:component]VmWatch", func() {
tests.FlagParse()

var err error
var virtCli kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_cloudinit_hook_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const cloudinitHookSidecarImage = "example-cloudinit-hook-sidecar"

var _ = Describe("CloudInitHookSidecars", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const (

var _ = Describe("[rfe_id:151][crit:high][vendor:[email protected]][level:component]CloudInit UserData", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import (

var _ = Describe("Configurations", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_gpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ func checkGPUDevice(vmi *v1.VirtualMachineInstance, gpuName string, prompt strin
}

var _ = Describe("GPU", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_headless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (

var _ = Describe("[rfe_id:609]VMIheadless", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient
var vmi *v1.VirtualMachineInstance
Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_hook_sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const hookSidecarImage = "example-hook-sidecar"

var _ = Describe("HookSidecars", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_ignition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (

var _ = Describe("[rfe_id:151][crit:high][vendor:[email protected]][level:component]IgnitionData", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_iothreads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import (
)

var _ = Describe("IOThreads", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func addNodeAffinityToVMI(vmi *v1.VirtualMachineInstance, nodeName string) {

var _ = Describe("[rfe_id:273][crit:high][vendor:[email protected]][level:component]VMIlifecycle", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import (

var _ = Describe("Health Monitoring", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_multiqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import (
)

var _ = Describe("MultiQueue", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
5 changes: 0 additions & 5 deletions tests/vmi_multus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package tests_test

import (
"flag"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -57,8 +56,6 @@ const (

var _ = Describe("Multus", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down Expand Up @@ -570,8 +567,6 @@ var _ = Describe("Multus", func() {

var _ = Describe("SRIOV", func() {

flag.Parse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import (

var _ = Describe("[rfe_id:694][crit:medium][vendor:[email protected]][level:component]Networking", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmi_slirp_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import (

var _ = Describe("Slirp Networking", func() {

tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
2 changes: 0 additions & 2 deletions tests/vmidefaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
)

var _ = Describe("VMIDefaults", func() {
tests.FlagParse()

var err error
var virtClient kubecli.KubevirtClient

Expand Down
Loading

0 comments on commit 6ea6468

Please sign in to comment.