Compose and nothing else, for the two workstations, where it is already installed by hand; the runtime, buildx and the group stay the docker module's. Nine Go tools: projects (with their directories from the containers' labels), ps, logs, a rendered config with secret-looking values redacted, and up, down, restart and pull by directory or name. Acts run as jobs inside the bundle, waited on for 18 s and followed with docker_compose_job, because an up that pulls outlasts a call. down never removes volumes.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestJobsAFastActIsAnsweredFinishedAndAFailedOneAsAnError(t *testing.T) {
|
|
using(t, func(line string, c Cmd) Result {
|
|
if c.Timeout != JobLimit {
|
|
t.Errorf("a job is held to JobLimit, not %s", c.Timeout)
|
|
}
|
|
if strings.Contains(line, "bad") {
|
|
return Result{Status: 2, Stderr: "it broke"}
|
|
}
|
|
return ok("done")
|
|
})
|
|
j, err := actAsJob(Cmd{Name: "good"})
|
|
if err != nil || j.Running || j.Status == nil || *j.Status != 0 || j.Output != "done" {
|
|
t.Fatalf("%+v %v", j, err)
|
|
}
|
|
if _, err := actAsJob(Cmd{Name: "bad"}); err == nil || !strings.Contains(err.Error(), "it broke") {
|
|
t.Fatalf("a failed job: %v", err)
|
|
}
|
|
got, err := jobByID(j.ID)
|
|
if err != nil || got.ID != j.ID {
|
|
t.Fatalf("by id: %+v %v", got, err)
|
|
}
|
|
if _, err := jobByID("nope"); err == nil {
|
|
t.Fatal("an unknown job")
|
|
}
|
|
if len(listJobs()) < 2 {
|
|
t.Fatal("listed")
|
|
}
|
|
}
|
|
|
|
func TestJobsASlowActIsAnsweredRunningWithItsID(t *testing.T) {
|
|
release := make(chan struct{})
|
|
using(t, func(line string, c Cmd) Result { <-release; return ok("") })
|
|
j := awaitJob(startJob(Cmd{Name: "slow"}), 50*time.Millisecond)
|
|
if !j.Running || j.ID == "" {
|
|
t.Fatalf("%+v", j)
|
|
}
|
|
close(release)
|
|
time.Sleep(50 * time.Millisecond)
|
|
got, _ := jobByID(j.ID)
|
|
if got.Running {
|
|
t.Fatalf("finished afterwards: %+v", got)
|
|
}
|
|
}
|