mirror of
https://github.com/status-im/consul.git
synced 2025-01-22 03:29:43 +00:00
37636eab71
* Implement the Catalog V2 controller integration container tests This now allows the container tests to import things from the root module. However for now we want to be very restrictive about which packages we allow importing. * Add an upgrade test for the new catalog Currently this should be dormant and not executed. However its put in place to detect breaking changes in the future and show an example of how to do an upgrade test with integration tests structured like catalog v2. * Make testutil.Retry capable of performing cleanup operations These cleanup operations are executed after each retry attempt. * Move TestContext to taking an interface instead of a concrete testing.T This allows this to be used on a retry.R or generally anything that meets the interface. * Move to using TestContext instead of background contexts Also this forces all test methods to implement the Cleanup method now instead of that being an optional interface. Co-authored-by: Daniel Upton <daniel@floppy.co>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package utils
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
)
|
|
|
|
// DockerExec simply shell out to the docker CLI binary on your host.
|
|
func DockerExec(args []string, stdout io.Writer) error {
|
|
return cmdExec("docker", "docker", args, stdout, "")
|
|
}
|
|
|
|
// DockerImageVersion retrieves the value of the org.opencontainers.image.version label from the specified image.
|
|
func DockerImageVersion(imageName string) (*version.Version, error) {
|
|
var b strings.Builder
|
|
err := cmdExec("docker", "docker", []string{"image", "inspect", "--format", `{{index .Config.Labels "org.opencontainers.image.version"}}`, imageName}, &b, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
output := b.String()
|
|
|
|
return version.NewVersion(strings.TrimSpace(output))
|
|
}
|
|
|
|
func cmdExec(name, binary string, args []string, stdout io.Writer, dir string) error {
|
|
if binary == "" {
|
|
panic("binary named " + name + " was not detected")
|
|
}
|
|
var errWriter bytes.Buffer
|
|
|
|
if stdout == nil {
|
|
stdout = os.Stdout
|
|
}
|
|
|
|
cmd := exec.Command(binary, args...)
|
|
if dir != "" {
|
|
cmd.Dir = dir
|
|
}
|
|
cmd.Stdout = stdout
|
|
cmd.Stderr = &errWriter
|
|
cmd.Stdin = nil
|
|
if err := cmd.Run(); err != nil {
|
|
return fmt.Errorf("could not invoke %q: %v : %s", name, err, errWriter.String())
|
|
}
|
|
|
|
return nil
|
|
}
|