63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package readiness
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go.maximumdirect.net/releasekit/internal/artifact"
|
|
"go.maximumdirect.net/releasekit/internal/releaseidentity"
|
|
)
|
|
|
|
func TestCommittedReadinessUsesCapturedModuleAndMainPackage(t *testing.T) {
|
|
repo := t.TempDir()
|
|
run := func(args ...string) string {
|
|
t.Helper()
|
|
cmd := exec.Command("git", args...)
|
|
cmd.Dir = repo
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("git %v: %v: %s", args, err, out)
|
|
}
|
|
return strings.TrimSpace(string(out))
|
|
}
|
|
run("init", "--initial-branch=main")
|
|
run("config", "user.name", "ReleaseKit Test")
|
|
run("config", "user.email", "releasekit@example.test")
|
|
if err := os.WriteFile(filepath.Join(repo, "go.mod"), []byte("module example.com/fixture\n\ngo 1.25.0\n"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(repo, "main.go"), []byte("package main\nfunc main() {}\n"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(repo, "required.txt"), []byte("captured"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
run("add", "--all")
|
|
run("commit", "-m", "capture inputs")
|
|
commit := run("rev-parse", "HEAD")
|
|
os.Remove(filepath.Join(repo, "main.go"))
|
|
os.Remove(filepath.Join(repo, "required.txt"))
|
|
os.WriteFile(filepath.Join(repo, "go.mod"), []byte("invalid working module"), 0600)
|
|
request := Request{RepositoryDir: repo, Commit: commit, Product: "Example", Context: "local", Source: &releaseidentity.SourceSpec{GoEnabled: true}, Operations: []string{"build"}, Build: &artifact.Settings{MainPackage: ".", BinaryName: "fixture", Targets: []artifact.Target{{OS: "linux", Arch: "amd64"}}}, RequiredFiles: []string{"required.txt", filepath.Join(repo, "required.txt")}}
|
|
report := Run(t.Context(), request)
|
|
for _, check := range report.Checks {
|
|
if check.Status == "failed" {
|
|
t.Fatalf("captured readiness failed: %+v", check)
|
|
}
|
|
}
|
|
request.Commit = ""
|
|
report = Run(t.Context(), request)
|
|
failed := false
|
|
for _, check := range report.Checks {
|
|
if check.Status == "failed" {
|
|
failed = true
|
|
}
|
|
}
|
|
if !failed {
|
|
t.Fatal("working readiness unexpectedly accepted missing and invalid inputs")
|
|
}
|
|
}
|