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

integration: Remove dangling container and container names #19

Merged
merged 5 commits into from
Sep 7, 2023
Merged
Changes from 4 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
48 changes: 24 additions & 24 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"reflect"
"strconv"
Expand All @@ -27,17 +26,14 @@ import (
"golang.org/x/sync/singleflight"
)

func TestMain(m *testing.M) {
cmd := exec.Command("podman", "run", "-p", "19085:9000", "quay.io/minio/minio", "server", "/data")
stderrPipe, err := cmd.StderrPipe()
if err != nil {
panic(err)
}
err = cmd.Start()
const containerName string = "ctile_integration_test_minio"
const testLogSaysPastTheEnd string = "oh no! we fell off the end of the log!"

func startContainer() {
pgporada marked this conversation as resolved.
Show resolved Hide resolved
_, err := exec.Command("podman", "run", "--rm", "--detach", "-p", "19085:9000", "--name", containerName, "quay.io/minio/minio", "server", "/data").Output()
if err != nil {
panic(err)
}
defer cmd.Process.Kill()
for i := 0; i < 1000; i++ {
_, err := net.Dial("tcp", "localhost:19085")
if errors.Is(err, syscall.ECONNREFUSED) {
Expand All @@ -50,25 +46,29 @@ func TestMain(m *testing.M) {
fmt.Println("minio is up")
break
}
code := m.Run()
err = cmd.Process.Signal(os.Interrupt)
if err != nil {
panic(err)
}
io.Copy(os.Stderr, stderrPipe)
processState, err := cmd.Process.Wait()
if err != nil {
panic(err)
}
if processState.ExitCode() != 0 {
panic(fmt.Errorf("minio exited with code %d", processState.ExitCode()))
}
os.Exit(code)
}

const testLogSaysPastTheEnd = "oh no! we fell off the end of the log!"
// cleanupContainer stops a running named container and removes its assigned
// name. This is helpful in the event that a container wasn't properly killed
// during a previous test run or if manual testing was being performed and not
// cleaned up.
func cleanupContainer() {
// Unconditionally stop the container.
_, _ = exec.Command("podman", "stop", containerName).Output()

// Unconditionally remove the container name if the operator did manual
// container testing, but didn't clean up the name.
_, _ = exec.Command("podman", "rm", containerName).Output()
}

func init() {
cleanupContainer()
startContainer()
pgporada marked this conversation as resolved.
Show resolved Hide resolved
}

func TestIntegration(t *testing.T) {
defer cleanupContainer()

// A test CT server that responds to get-entries requests with appropriately JSON-formatted
// data, where base64-decoding the LeafInput and ExtraData fields yields a binary encoding
// of the position of the given element.
Expand Down