This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdots_test.go
71 lines (63 loc) · 1.98 KB
/
dots_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package dots
import (
"bytes"
"github.com/cucumber/cucumber-messages-go/v5"
"github.com/fatih/color"
gio "github.com/gogo/protobuf/io"
"github.com/stretchr/testify/require"
"io/ioutil"
"strings"
"testing"
)
func TestAllResultTypes(t *testing.T) {
stdin := &bytes.Buffer{}
writer := gio.NewDelimitedWriter(stdin)
writer.WriteMsg(newTestStepFinished(messages.TestResult_FAILED))
writer.WriteMsg(newTestStepFinished(messages.TestResult_SKIPPED))
writer.WriteMsg(newTestStepFinished(messages.TestResult_UNDEFINED))
writer.WriteMsg(newTestStepFinished(messages.TestResult_AMBIGUOUS))
writer.WriteMsg(newTestStepFinished(messages.TestResult_PASSED))
writer.WriteMsg(newTestStepFinished(messages.TestResult_PENDING))
writer.WriteMsg(newTestHookFinished(messages.TestResult_PASSED))
writer.WriteMsg(newTestHookFinished(messages.TestResult_FAILED))
// Write to disk, so it can be used for a manual test
b := stdin.Bytes()
err := ioutil.WriteFile("all-results.bin", b, 0644)
require.NoError(t, err)
stdout := &bytes.Buffer{}
ProcessMessages(stdin, stdout)
require.EqualValues(t,
strings.Join([]string{
color.New(color.FgRed).Sprint("F"),
color.New(color.FgCyan).Sprint("-"),
color.New(color.FgYellow).Sprint("U"),
color.New(color.FgMagenta).Sprint("A"),
color.New(color.FgGreen).Sprint("."),
color.New(color.FgYellow).Sprint("P"),
color.New(color.FgRed).Sprint("H"),
"\n",
}, ""),
stdout.String())
}
func newTestStepFinished(status messages.TestResult_Status) *messages.Envelope {
return &messages.Envelope{
Message: &messages.Envelope_TestStepFinished{
TestStepFinished: &messages.TestStepFinished{
TestResult: &messages.TestResult{
Status: status,
},
},
},
}
}
func newTestHookFinished(status messages.TestResult_Status) *messages.Envelope {
return &messages.Envelope{
Message: &messages.Envelope_TestHookFinished{
TestHookFinished: &messages.TestHookFinished{
TestResult: &messages.TestResult{
Status: status,
},
},
},
}
}