Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
doc: fix running Kubernetes test with CUE_UPDATE=1
Browse files Browse the repository at this point in the history
This is a temporary sticking plaster that allows go test to be run on
the Kubernetes tutorial once again when CUE_UPDATE=1 is set. We allow
the running of go get under the same conditions as cue get.

The main work to fix up this tutorial is still captured in #824.

Change-Id: Ia05dc40fae96891145ff2da0ba2c0db6a908fd1e
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9182
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
myitcv committed Mar 29, 2021
1 parent efd22f6 commit 6195171
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions doc/tutorial/kubernetes/tut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,8 @@ func TestTutorial(t *testing.T) {
// The test environment won't work in all environments. We create
// a fake go.mod so that Go will find the module root. By default
// we won't set it.
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
cmd := exec.Command("go", "mod", "init", "cuelang.org/dummy")
b, err := cmd.CombinedOutput()
logf(t, string(b))
if err != nil {
t.Fatal(err)
}
out := execute(t, dir, "go", "mod", "init", "cuelang.org/dummy")
logf(t, "%s", out)
} else {
// We only fetch new kubernetes files with when updating.
err := copy.Dir(load.GenPath("quick"), load.GenPath(dir))
Expand Down Expand Up @@ -198,6 +191,14 @@ func TestTutorial(t *testing.T) {
if err != nil {
t.Fatal(err)
}
case strings.HasPrefix(cmd, "go "):
if !cuetest.UpdateGoldenFiles && strings.HasPrefix(cmd, "go get") {
// Don't fetch stuff in normal mode.
break
}

out := execute(t, wd, splitArgs(t, cmd)...)
logf(t, "%s", out)
}
}
}
Expand Down Expand Up @@ -312,6 +313,27 @@ type config struct {
Golden string
}

// execute executes the given command in the given directory
func execute(t *testing.T, dir string, args ...string) string {
old, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err = os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer func() { os.Chdir(old) }()

logf(t, "Executing command: %s", strings.Join(args, " "))

cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("failed to run [%v] in %s: %v\n%s", cmd, dir, err, out)
}
return string(out)
}

// run executes the given command in the given directory and reports any
// errors comparing it to the gold standard.
func run(t *testing.T, dir, command string, cfg *config) {
Expand Down

0 comments on commit 6195171

Please sign in to comment.