MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestCached

Function TestCached

cmd/testwrapper/testwrapper_test.go:393–451  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

391}
392
393func TestCached(t *testing.T) {
394 t.Parallel()
395
396 // Construct our trivial package.
397 pkgDir := t.TempDir()
398 goVersion := runtime.Version()
399 goVersion = strings.TrimPrefix(goVersion, "go")
400 goVersion, _, _ = strings.Cut(goVersion, "-X:") // map 1.26.1-X:nogreenteagc to 1.26.1
401
402 goMod := fmt.Sprintf(`module example.com
403
404go %s
405`, goVersion)
406 test := `package main
407import "testing"
408
409func TestCached(t *testing.T) {}
410`
411
412 for f, c := range map[string]string{
413 "go.mod": goMod,
414 "cached_test.go": test,
415 } {
416 err := os.WriteFile(filepath.Join(pkgDir, f), []byte(c), 0o644)
417 if err != nil {
418 t.Fatalf("writing package: %s", err)
419 }
420 }
421
422 for name, args := range map[string][]string{
423 "without_flags": {"./..."},
424 "with_short": {"./...", "-short"},
425 "with_coverprofile": {"./...", "-coverprofile=" + filepath.Join(t.TempDir(), "coverage.out")},
426 } {
427 t.Run(name, func(t *testing.T) {
428 var (
429 out []byte
430 err error
431 )
432 for range 2 {
433 cmd := cmdTestwrapper(t, args...)
434 cmd.Dir = pkgDir
435 out, err = cmd.CombinedOutput()
436 if err != nil {
437 t.Fatalf("testwrapper ./...: expected no error but got: %v; output was:\n%s", err, out)
438 }
439 }
440
441 want := []byte("ok\texample.com\t(cached)")
442 if !bytes.Contains(out, want) {
443 t.Fatalf("wanted output containing %q but got:\n%s", want, out)
444 }
445
446 if testing.Verbose() {
447 t.Logf("success - output:\n%s", out)
448 }
449 })
450 }

Callers

nothing calls this directly

Calls 9

cmdTestwrapperFunction · 0.85
CombinedOutputMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
FatalfMethod · 0.65
RunMethod · 0.65
LogfMethod · 0.65
VersionMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…