Fix error writing coverage when running tests (#10278)

Intended to fix this error we are seeing in CI:

```
error generating coverage report: write |1: file already closed
```

It seems like perhaps a change in the way the test coverage is reported
in a recent Go version has interacted with the closing of stdout in
these tests.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Added/updated tests
This commit is contained in:
Zach Wasserman
2023-03-02 17:11:15 -08:00
committed by GitHub
parent 1e9c928628
commit ca2e30e59c
2 changed files with 4 additions and 1 deletions
+2
View File
@@ -41,6 +41,7 @@ func TestConvertFileOutput(t *testing.T) {
func TestConvertFileStdout(t *testing.T) {
r, w, _ := os.Pipe()
oldStdout := os.Stdout
os.Stdout = w
// setup the cli and the convert command
@@ -60,6 +61,7 @@ func TestConvertFileStdout(t *testing.T) {
err = app.Run(args)
require.NoError(t, err)
os.Stdout = oldStdout
w.Close()
out, _ := ioutil.ReadAll(r)
require.Equal(t, expected, out)
+2 -1
View File
@@ -13,7 +13,6 @@ import (
"github.com/fleetdm/fleet/v4/server/service"
"github.com/fleetdm/fleet/v4/server/service/schedule"
kitlog "github.com/go-kit/kit/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -50,6 +49,7 @@ func TestTrigger(t *testing.T) {
}
r, w, _ := os.Pipe()
oldStdout := os.Stdout
os.Stdout = w
_, _ = runServerWithMockedDS(t, &service.TestServerOpts{
@@ -78,6 +78,7 @@ func TestTrigger(t *testing.T) {
assert.Equal(t, "", runAppForTest(t, c.args))
}
os.Stdout = oldStdout
w.Close()
out, _ := ioutil.ReadAll(r)
outlines := strings.Split(string(out), "\n")