Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: skip tests unless running docker on linux #3611

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions govc/test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ require_docker() {
if ! docker version ; then
skip "docker client not installed"
fi

if [ "$(uname)" != "Linux" ] ; then
skip "docker tests require linux"
fi
}

docker_name() {
Expand Down
6 changes: 6 additions & 0 deletions guest/toolbox/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@ package toolbox_test

import (
"context"
"fmt"
"os"
"os/exec"

"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/guest/toolbox"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/test"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)

func ExampleClient_Run() {
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
if !test.HasDocker() {
fmt.Println("Linux")
return nil
}
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions simulator/container_host_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/vmware/govmomi/simulator/esx"
"github.com/vmware/govmomi/test"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
)
Expand Down Expand Up @@ -161,6 +162,10 @@ func TestPerHostOptionManager(t *testing.T) {
}

func TestHostContainerBacking(t *testing.T) {
if !test.HasDocker() {
t.Skip("requires docker on linux")
}

m := ESX()

defer m.Remove()
Expand Down Expand Up @@ -188,6 +193,10 @@ func TestHostContainerBacking(t *testing.T) {
}

func TestMultipleSimHost(t *testing.T) {
if !test.HasDocker() {
t.Skip("requires docker on linux")
}

m := ESX()

defer m.Remove()
Expand Down
13 changes: 5 additions & 8 deletions simulator/container_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/test"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)
Expand Down Expand Up @@ -105,9 +106,8 @@ func validateNginxContainer(t *testing.T, vm *object.VirtualMachine, expected st
// 3. Confirm docker container present that matches expectations
func TestCreateVMWithContainerBacking(t *testing.T) {
Test(func(ctx context.Context, c *vim25.Client) {
if _, err := exec.LookPath("docker"); err != nil {
fmt.Println("0 diff")
t.Skip("docker client binary not on PATH")
if !test.HasDocker() {
t.Skip("requires docker on linux")
return
}

Expand Down Expand Up @@ -177,7 +177,6 @@ func TestCreateVMWithContainerBacking(t *testing.T) {
task, _ = vm.Destroy(ctx)
_ = task.Wait(ctx)
})
// Output: 0 diff
}

// 1. Create VM without ExtraConfig args for container backing
Expand All @@ -186,9 +185,8 @@ func TestCreateVMWithContainerBacking(t *testing.T) {
// 4. Confirm docker container present that matches expectations
func TestUpdateVMAddContainerBacking(t *testing.T) {
Test(func(ctx context.Context, c *vim25.Client) {
if _, err := exec.LookPath("docker"); err != nil {
fmt.Println("0 diff")
t.Skip("docker client binary not on PATH")
if !test.HasDocker() {
t.Skip("requires docker on linux")
return
}

Expand Down Expand Up @@ -255,5 +253,4 @@ func TestUpdateVMAddContainerBacking(t *testing.T) {
task, _ = vm.Destroy(ctx)
_ = task.Wait(ctx)
})
// Output: 0 diff
}
3 changes: 2 additions & 1 deletion simulator/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator"
"github.com/vmware/govmomi/test"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)
Expand Down Expand Up @@ -88,7 +89,7 @@ func Example_setVirtualMachineProperties() {
// Tie a docker container to the lifecycle of a vcsim VM
func Example_runContainer() {
simulator.Test(func(ctx context.Context, c *vim25.Client) {
if _, err := exec.LookPath("docker"); err != nil {
if !test.HasDocker() {
fmt.Println("0 diff")
return
}
Expand Down
16 changes: 14 additions & 2 deletions test/helper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2024 VMware, Inc. All Rights Reserved.

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
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,
Expand All @@ -20,6 +20,8 @@ import (
"context"
"net/url"
"os"
"os/exec"
"runtime"
"testing"

"github.com/vmware/govmomi/vim25"
Expand All @@ -28,6 +30,16 @@ import (
"github.com/vmware/govmomi/vim25/types"
)

func HasDocker() bool {
if runtime.GOOS != "linux" {
return false
}
if _, err := exec.LookPath("docker"); err != nil {
return false
}
return true
}

// URL parses the GOVMOMI_TEST_URL environment variable if set.
func URL() *url.URL {
s := os.Getenv("GOVMOMI_TEST_URL")
Expand Down
Loading