Separate example setup from synthetic test releases
This commit is contained in:
54
cmd/releasekit/example_source_test.go
Normal file
54
cmd/releasekit/example_source_test.go
Normal file
@@ -0,0 +1,54 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -316,6 +316,13 @@ func newWorkflowRepository(t *testing.T, example string) string {
|
||||
t.Fatal(err)
|
||||
}
|
||||
copyExampleTree(t, example, repository)
|
||||
for _, selection := range []struct{ directory, module string }{
|
||||
{".", "example.com/multi-module-consumer"},
|
||||
{"integrations/ckconfig", "example.com/multi-module-consumer/integrations/ckconfig"},
|
||||
{"integrations/core/v2", "example.com/multi-module-consumer/integrations/core/v2"},
|
||||
} {
|
||||
writeRepositoryFile(t, repository, selection.directory+"/go.mod", workflowModuleFile(selection.module, "v0.2.197"))
|
||||
}
|
||||
cliGitRun(t, repository, "init", "--initial-branch=main")
|
||||
cliGitRun(t, repository, "config", "user.name", "ReleaseKit Test")
|
||||
cliGitRun(t, repository, "config", "user.email", "releasekit@example.test")
|
||||
|
||||
Reference in New Issue
Block a user