tstest/integration/vms: codegen for top level tests (#2441)

This moves the distribution definitions into a maintainable hujson file
instead of just existing as constants in `distros.go`. Comments are
maintained from the inline definitions.

This uses jennifer[1] for hygenic source tree creation. This allows us
to generate a unique top-level test for each VM run. This should
hopefully help make the output of `go test` easier to read.

This also separates each test out into its own top-level test so that we
can better track the time that each distro takes. I really wish there
was a way to have the `test_codegen.go` file _always_ run as a part of
the compile process instead of having to rely on people remembering to
run `go generate`, but I am limited by my tools.

This will let us remove the `-distro-regex` flag and use `go test -run`
to pick which distros are run.

Signed-off-by: Christine Dodrill <xe@tailscale.com>
This commit is contained in:
Christine Dodrill
2021-07-16 15:25:16 -04:00
committed by GitHub
parent 391207bbcf
commit 798b0da470
11 changed files with 527 additions and 154 deletions

View File

@@ -169,7 +169,7 @@ func copyUnit(t *testing.T, bins *integration.Binaries) {
func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string {
copyUnit(t, h.bins)
dir := t.TempDir()
fname := filepath.Join(dir, d.name+".nix")
fname := filepath.Join(dir, d.Name+".nix")
fout, err := os.Create(fname)
if err != nil {
t.Fatal(err)
@@ -196,10 +196,10 @@ func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string {
os.MkdirAll(outpath, 0755)
t.Cleanup(func() {
os.RemoveAll(filepath.Join(outpath, d.name)) // makes the disk image a candidate for GC
os.RemoveAll(filepath.Join(outpath, d.Name)) // makes the disk image a candidate for GC
})
cmd := exec.Command("nixos-generate", "-f", "qcow", "-o", filepath.Join(outpath, d.name), "-c", fname)
cmd := exec.Command("nixos-generate", "-f", "qcow", "-o", filepath.Join(outpath, d.Name), "-c", fname)
if *verboseNixOutput {
cmd.Stdout = logger.FuncWriter(t.Logf)
cmd.Stderr = logger.FuncWriter(t.Logf)
@@ -214,16 +214,16 @@ func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string {
cmd.Stderr = fout
defer fout.Close()
}
cmd.Env = append(os.Environ(), "NIX_PATH=nixpkgs="+d.url)
cmd.Env = append(os.Environ(), "NIX_PATH=nixpkgs="+d.URL)
cmd.Dir = outpath
t.Logf("running %s %#v", "nixos-generate", cmd.Args)
if err := cmd.Run(); err != nil {
t.Fatalf("error while making NixOS image for %s: %v", d.name, err)
t.Fatalf("error while making NixOS image for %s: %v", d.Name, err)
}
if !*verboseNixOutput {
t.Log("done")
}
return filepath.Join(outpath, d.name, "nixos.qcow2")
return filepath.Join(outpath, d.Name, "nixos.qcow2")
}