MCPcopy
hub / github.com/sirupsen/logrus / TestHandler

Function TestHandler

alt_exit_test.go:74–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

72}
73
74func TestHandler(t *testing.T) {
75 testprog := testprogleader
76 testprog = append(testprog, getPackage()...)
77 testprog = append(testprog, testprogtrailer...)
78 tempDir, err := os.MkdirTemp("", "test_handler")
79 if err != nil {
80 log.Fatalf("can't create temp dir. %q", err)
81 }
82 defer os.RemoveAll(tempDir)
83
84 gofile := filepath.Join(tempDir, "gofile.go")
85 if err := os.WriteFile(gofile, testprog, 0666); err != nil {
86 t.Fatalf("can't create go file. %q", err)
87 }
88
89 outfile := filepath.Join(tempDir, "outfile.out")
90 arg := time.Now().UTC().String()
91 err = exec.Command("go", "run", gofile, outfile, arg).Run()
92 if err == nil {
93 t.Fatalf("completed normally, should have failed")
94 }
95
96 data, err := os.ReadFile(outfile)
97 if err != nil {
98 t.Fatalf("can't read output file %s. %q", outfile, err)
99 }
100
101 if string(data) != arg {
102 t.Fatalf("bad data. Expected %q, got %q", data, arg)
103 }
104}
105
106// getPackage returns the name of the current package, which makes running this
107// test in a fork simpler

Callers

nothing calls this directly

Calls 3

getPackageFunction · 0.85
FatalfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected