55 lines
2.3 KiB
Go
55 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestMultiModuleExampleSetupUsesCurrentSourceTool(t *testing.T) {
|
|
root := cliRepositoryRoot(t)
|
|
repository := newCLIRepository(t)
|
|
copyExampleTree(t, filepath.Join(root, "examples", "multi-module"), repository)
|
|
const module = "gitea.maximumdirect.net/eric/ReleaseKit"
|
|
environment := append(os.Environ(), "GOTOOLCHAIN=local", "GOWORK=off", "GOPROXY=off", "GOSUMDB=off", "GOFLAGS=")
|
|
goCommand := func(directory string, args ...string) string {
|
|
t.Helper()
|
|
command := exec.Command("go", args...)
|
|
command.Dir, command.Env = directory, environment
|
|
output, err := command.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("go %q: %v\n%s", args, err, output)
|
|
}
|
|
return string(output)
|
|
}
|
|
selections := []struct {
|
|
directory, profile, product, version string
|
|
}{
|
|
{".", "releasekit-root.json", "Example Consumer", "v1.2.3"},
|
|
{"integrations/ckconfig", "releasekit-ckconfig.json", "Example Consumer Integration", "v1.2.3"},
|
|
{"integrations/core/v2", "releasekit-core-v2.json", "Example Consumer Core v2", "v2.1.0"},
|
|
}
|
|
for _, selected := range selections {
|
|
directory := filepath.Join(repository, filepath.FromSlash(selected.directory))
|
|
if selected.directory != "integrations/core/v2" {
|
|
writeRepositoryFile(t, repository, selected.directory+"/source.go", "package candidate\n")
|
|
}
|
|
goCommand(directory, "mod", "edit", "-require="+module+"@v0.0.0", "-replace="+module+"="+root, "-tool="+module+"/cmd/releasekit")
|
|
goCommand(directory, "mod", "tidy")
|
|
writeRepositoryFile(t, repository, selected.directory+"/docs/releases/"+selected.version+".md", "# "+selected.product+" "+selected.version+"\n\nSource verification fixture.\n")
|
|
}
|
|
cliGitRun(t, repository, "add", ".")
|
|
cliGitRun(t, repository, "commit", "-m", "Select current source in disposable example")
|
|
for _, selected := range selections {
|
|
output := goCommand(filepath.Join(repository, filepath.FromSlash(selected.directory)), "tool", "releasekit", "check", "--config", selected.profile, selected.version)
|
|
if !strings.Contains(output, "is valid") {
|
|
t.Fatalf("source-selected check output=%s", output)
|
|
}
|
|
}
|
|
if status := cliGitOutput(t, repository, "status", "--porcelain"); status != "" {
|
|
t.Fatalf("source verification changed committed fixture: %s", status)
|
|
}
|
|
}
|