Skip to content

Commit

Permalink
wip: start on run on real e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Jul 12, 2023
1 parent 026129e commit 490cf77
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 22 deletions.
66 changes: 66 additions & 0 deletions e2e/podman/input/registry-configs.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# This job runs after the private registry is up and running, when we know
# address and port provided by the bridge network. It is a sysbatch job
# that writes
# - /usr/local/bin/docker-credential-test.sh
# - /etc/docker-registry-auth.json

job "registry-configs" {
type = "sysbatch"

constraint {
attribute {
attribute = "${attr.kernel.name}"
value = "linux"
}
}

group "group" {
reschedule {
attempts = 0
unlimited = false
}
}

task "write-script" {
driver = "pledge"

template {
destination = "local/docker-credential-test.sh"
data = <<EOH
#!/usr/bin/env bash
set -euo pipefail
value=$(cat /dev/stdin)
username="auth_helper_user"
password="auth_helper_pass"
case "${value}" in
docker.io/*)
echo "must use local registry"
exit 3
;;
*)
echo "{\"Username\": \"$username\", \"Secret\": \"$password\"}"
exit 0
;;
esac
EOH
}

config {
command = "/usr/bin/mv"
args = [
"local/docker-crediential-test.sh",
"/usr/local/bin/docker-credential-test.sh",
]
promises = "stdio rpath wpath cpath"
unveil = ["r:local/docker-credential-test.sh", "wc:/usr/local/bin"]
}

resources {
cpu = 100
memory = 32
}
}
}
42 changes: 20 additions & 22 deletions e2e/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,29 @@ func TestPodman(t *testing.T) {
cluster3.LinuxClients(1),
)

t.Run("testRedis", testRedis)
t.Run("testAuthBasic", testAuthBasic)
t.Run("testAuthFileStatic", testAuthFileStatic)
runRegistry(t)

// t.Run("testRedis", testRedis)
// t.Run("testAuthBasic", testAuthBasic)
// t.Run("testAuthFileStatic", testAuthFileStatic)
t.Run("testAuthHelper", testAuthHelper)
}

func findService(t *testing.T, name string) (string, int) {
services, _, err := e2eutil.NomadClient(t).Services().Get(name, nil)
must.NoError(t, err, must.Sprintf("failed to find %q service", name))
must.Len(t, 1, services, must.Sprintf("expected 1 %q service", name))
return services[0].Address, services[0].Port
}

func runRegistry(t *testing.T) {
_, regCleanup := jobs3.Submit(t,
"./input/registry.hcl",
jobs3.Timeout(40*time.Second), // pulls an image
)
t.Cleanup(regCleanup)
}

func testRedis(t *testing.T) {
job, cleanup := jobs3.Submit(t, "./input/redis.hcl")
t.Cleanup(cleanup)
Expand All @@ -34,13 +51,6 @@ func testRedis(t *testing.T) {
must.StrContains(t, logs.Stdout, "oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo")
}

func findService(t *testing.T, name string) (string, int) {
services, _, err := e2eutil.NomadClient(t).Services().Get(name, nil)
must.NoError(t, err, must.Sprintf("failed to find %q service", name))
must.Len(t, 1, services, must.Sprintf("expected 1 %q service", name))
return services[0].Address, services[0].Port
}

func testAuthBasic(t *testing.T) {
_, regCleanup := jobs3.Submit(t,
"./input/registry.hcl",
Expand All @@ -63,12 +73,6 @@ func testAuthBasic(t *testing.T) {
}

func testAuthFileStatic(t *testing.T) {
_, regCleanup := jobs3.Submit(t,
"./input/registry.hcl",
jobs3.Timeout(40*time.Second), // pulls an image
)
t.Cleanup(regCleanup)

// find the private registry service
regAddr, regPort := findService(t, "registry")

Expand All @@ -84,12 +88,6 @@ func testAuthFileStatic(t *testing.T) {
}

func testAuthHelper(t *testing.T) {
_, regCleanup := jobs3.Submit(t,
"./input/registry.hcl",
jobs3.Timeout(40*time.Second), // pulls an image
)
t.Cleanup(regCleanup)

// find the private registry service
regAddr, regPort := findService(t, "registry")

Expand Down

0 comments on commit 490cf77

Please sign in to comment.