mirror of
https://github.com/containers/skopeo.git
synced 2025-09-10 11:09:47 +00:00
Add integration tests for (skopeo copy) against the Atomic Registry
This builds from the image-signatures-rest branch for https://github.com/openshift/origin/pull/9181 . Testing push, pull, streaming. Does not test working with the other Docker registries built in Dockerfile; I will leave that to the author of that code :) Note that this relies on an internet connection for pulling from the Docker Hub (which is incidentally tested by that); pushing to no Docker Registry, neither local nor Hub, is tested by this. The tests only run in a container because the (oc login) / (docker login)-like code modifies files in a home directory; the new SKOPEO_CONTAINER_TESTS environment variable should protect against accidental non-container runs.
This commit is contained in:
@@ -2,8 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
@@ -38,6 +40,15 @@ func consumeAndLogOutputs(c *check.C, id string, cmd *exec.Cmd) {
|
||||
consumeAndLogOutputStream(c, id+" stderr", stderr, err)
|
||||
}
|
||||
|
||||
// combinedOutputOfCommand runs a command as if exec.Command().CombinedOutput(), verifies that the exit status is 0, and returns the output,
|
||||
// or terminates c on failure.
|
||||
func combinedOutputOfCommand(c *check.C, name string, args ...string) string {
|
||||
c.Logf("Running %s %s", name, strings.Join(args, " "))
|
||||
out, err := exec.Command(name, args...).CombinedOutput()
|
||||
c.Assert(err, check.IsNil, check.Commentf("%s", out))
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// assertSkopeoSucceeds runs a skopeo command as if exec.Command().CombinedOutput, verifies that the exit status is 0,
|
||||
// and optionally that the output matches a multi-line regexp if it is nonempty;
|
||||
// or terminates c on failure
|
||||
@@ -77,3 +88,59 @@ func runCommandWithInput(c *check.C, input string, name string, args ...string)
|
||||
err = cmd.Wait()
|
||||
c.Assert(err, check.IsNil)
|
||||
}
|
||||
|
||||
// isPortOpen returns true iff the specified port on localhost is open.
|
||||
func isPortOpen(port int) bool {
|
||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: port})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
conn.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
// newPortChecker sets up a portOpen channel which will receive true after the specified port is open.
|
||||
// The checking can be aborted by sending a value to the terminate channel, which the caller should
|
||||
// always do using
|
||||
// defer func() {terminate <- true}()
|
||||
func newPortChecker(c *check.C, port int) (portOpen <-chan bool, terminate chan<- bool) {
|
||||
portOpenBidi := make(chan bool)
|
||||
// Buffered, so that sending a terminate request after the goroutine has exited does not block.
|
||||
terminateBidi := make(chan bool, 1)
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
c.Logf("Port checker for port %d exiting", port)
|
||||
}()
|
||||
for {
|
||||
c.Logf("Checking for port %d...", port)
|
||||
if isPortOpen(port) {
|
||||
c.Logf("Port %d open", port)
|
||||
portOpenBidi <- true
|
||||
return
|
||||
}
|
||||
c.Logf("Sleeping for port %d", port)
|
||||
sleepChan := time.After(100 * time.Millisecond)
|
||||
select {
|
||||
case <-sleepChan: // Try again
|
||||
c.Logf("Sleeping for port %d done, will retry", port)
|
||||
case <-terminateBidi:
|
||||
c.Logf("Check for port %d terminated", port)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return portOpenBidi, terminateBidi
|
||||
}
|
||||
|
||||
// modifyEnviron modifies os.Environ()-like list of name=value assignments to set name to value.
|
||||
func modifyEnviron(env []string, name, value string) []string {
|
||||
prefix := name + "="
|
||||
res := []string{}
|
||||
for _, e := range env {
|
||||
if !strings.HasPrefix(e, prefix) {
|
||||
res = append(res, e)
|
||||
}
|
||||
}
|
||||
return append(res, prefix+value)
|
||||
}
|
||||
|
Reference in New Issue
Block a user