Skip to content
quarry Artifact [c4ce00e3a8]
Login

Artifact [c4ce00e3a8]

Artifact c4ce00e3a847c2313bb39780bac9f130ca873b731e30692a1f6fa2e861e151a6:


package main

import (
	"os"
	"os/exec"
	"path/filepath"
	"testing"
)

func TestMain(m *testing.M) {
	if os.Getenv("QUARRY_RUNNER_AS_MAIN") == "1" {
		os.Args = append([]string{"quarry-runner"}, os.Args[1:]...)
		main()
		return
	}
	os.Exit(m.Run())
}

// `quarry-runner pickup new` is the pickup client: it writes a 0600 key
// and prints a 64-hex code, so the small runner binary carries it.
func TestRunnerBinaryCarriesPickupNew(t *testing.T) {
	dir := t.TempDir()
	cmd := exec.Command(os.Args[0], "pickup", "new", "--dir", dir)
	cmd.Env = append(os.Environ(), "QUARRY_RUNNER_AS_MAIN=1")
	out, err := cmd.Output()
	if err != nil {
		t.Fatalf("FAIL: pickup new: %v", err)
	}
	if len(out) != 65 {
		t.Errorf("FAIL: printed %d bytes, want a 64-hex code and a newline", len(out))
	}
	entries, _ := os.ReadDir(dir)
	if len(entries) != 1 {
		t.Fatalf("FAIL: %d files written, want the key", len(entries))
	}
	if fi, _ := os.Stat(filepath.Join(dir, entries[0].Name())); fi.Mode().Perm() != 0o600 {
		t.Errorf("FAIL: key mode %v, want 0600", fi.Mode().Perm())
	}
	if !t.Failed() {
		t.Log("ok")
	}
}