Skip to content

Commit 63bc169

Browse files
committed
WIP: add synchronous execution of file tests and panic on file err
1 parent cc7d484 commit 63bc169

11 files changed

Lines changed: 25 additions & 165 deletions

File tree

go.mod298498081.tmp

Lines changed: 0 additions & 27 deletions
This file was deleted.

go.mod427131847.tmp

Lines changed: 0 additions & 27 deletions
This file was deleted.

go.mod939984059.tmp

Lines changed: 0 additions & 27 deletions
This file was deleted.

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
5252
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
5353
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
5454
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
55+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
5556
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
5657
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
58+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
5759
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
5860
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e h1:9MlwzLdW7QSDrhDjFlsEYmxpFyIoXmYRon3dt0io31k=
5961
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
@@ -112,6 +114,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv
112114
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
113115
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA=
114116
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
117+
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 h1:HmbHVPwrPEKPGLAcHSrMe6+hqSUlvZU0rab6x5EXfGU=
115118
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
116119
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
117120
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
@@ -123,6 +126,7 @@ golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGm
123126
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
124127
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
125128
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
129+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
126130
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
127131
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
128132
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=

pkg/app/app.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const (
1313
type AddCommandContext struct {
1414
Verbose bool
1515
NoColor bool
16-
FileOrder bool
1716
Concurrent int
1817
}
1918

@@ -22,7 +21,6 @@ func NewAddContextFromCli(c *cli.Context) AddCommandContext {
2221
return AddCommandContext{
2322
Verbose: c.Bool("verbose"),
2423
NoColor: c.Bool("no-color"),
25-
FileOrder: c.Bool("file-order"),
2624
Concurrent: c.Int("concurrent"),
2725
}
2826
}

pkg/app/test_command.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestCommand(input string, title string, ctx AddCommandContext) error {
3333
if inputType.IsDir() {
3434
fmt.Println("Starting test against directory: " + input + "...")
3535
fmt.Println("")
36+
// since no handling of file errors occur should we not allow title
3637
results, err = testDir(input, title)
3738
} else {
3839
fmt.Println("Starting test file " + input + "...")
@@ -44,7 +45,7 @@ func TestCommand(input string, title string, ctx AddCommandContext) error {
4445
return fmt.Errorf(err.Error())
4546
}
4647

47-
out := output.NewCliOutput(!ctx.NoColor, ctx.FileOrder)
48+
out := output.NewCliOutput(!ctx.NoColor)
4849
if !out.Start(results) {
4950
return fmt.Errorf("Test suite failed, use --verbose for more detailed output")
5051
}
@@ -61,24 +62,26 @@ func testDir(directory string, title string) (<-chan runtime.TestResult, error)
6162
results := make(chan runtime.TestResult)
6263
var wg sync.WaitGroup
6364

64-
for _, f := range files {
65-
wg.Add(1)
66-
67-
go func(f os.FileInfo) {
68-
defer wg.Done()
65+
wg.Add(1)
66+
go func() {
67+
defer wg.Done()
68+
for _, f := range files {
69+
// Skip reading dirs for now. Should we also check valid file types?
70+
if f.IsDir() {
71+
continue
72+
}
6973

7074
fileResults, err := testFile(directory+"/"+f.Name(), title)
7175
if err != nil {
72-
results <- runtime.TestResult{FileError: err, FileName: f.Name()}
73-
return
76+
panic(fmt.Sprintf("%s: %s", f.Name(), err))
7477
}
7578

7679
for r := range fileResults {
7780
r.FileName = f.Name()
78-
results <- r //fan in results
81+
results <- r
7982
}
80-
}(f)
81-
}
83+
}
84+
}()
8285

8386
go func(ch chan runtime.TestResult) {
8487
wg.Wait()

pkg/app/test_command_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ func Test_TestCommand_Dir(t *testing.T) {
5656
}
5757
}
5858

59-
func Test_TestCommand_Dir_With_Title(t *testing.T) {
60-
err := TestCommand("../../examples", "it should fail", AddCommandContext{})
61-
62-
if runtime.GOOS == "windows" {
63-
assert.Contains(t, err.Error(), "Test suite failed, use --verbose for more detailed output")
64-
} else {
65-
assert.Equal(t, "Test suite failed, use --verbose for more detailed output", err.Error())
66-
}
67-
}
68-
6959
func captureOutput(f func()) string {
7060
reader, writer, err := os.Pipe()
7161
if err != nil {

pkg/output/cli.go

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import (
66
"log"
77
"os"
88
run "runtime"
9-
"sort"
109
"time"
1110

1211
"github.com/SimonBaeumer/commander/pkg/runtime"
13-
"github.com/SimonBaeumer/commander/pkg/suite"
1412
"github.com/logrusorgru/aurora"
1513
)
1614

@@ -20,15 +18,13 @@ var au aurora.Aurora
2018
type OutputWriter struct {
2119
out io.Writer
2220
color bool
23-
order bool
2421
}
2522

2623
// NewCliOutput creates a new OutputWriter with a stdout writer
27-
func NewCliOutput(color bool, order bool) OutputWriter {
24+
func NewCliOutput(color bool) OutputWriter {
2825
return OutputWriter{
2926
out: os.Stdout,
3027
color: color,
31-
order: order,
3228
}
3329
}
3430

@@ -39,36 +35,17 @@ func (w *OutputWriter) Start(results <-chan runtime.TestResult) bool {
3935
au = aurora.NewAurora(false)
4036
}
4137

42-
var failed int
43-
var fileErrors []error
38+
failed := 0
4439
var testResults []runtime.TestResult
4540
start := time.Now()
4641

4742
for r := range results {
48-
if r.FileError != nil {
49-
//only append FileErrors that are not title Errors
50-
if _, ok := r.FileError.(*suite.TitleErr); !ok {
51-
fileErrors = append(fileErrors, fmt.Errorf("[%s] %s", r.FileName, r.FileError))
52-
}
53-
continue
54-
}
5543
testResults = append(testResults, r)
56-
if !w.order { //if no order print now
57-
failed += w.readResult(r)
58-
}
44+
failed += w.printResult(r)
5945
}
6046

6147
duration := time.Since(start)
6248

63-
if w.order { //Maintain file order
64-
sort.SliceStable(testResults, func(i, j int) bool {
65-
return testResults[i].FileName < testResults[j].FileName
66-
})
67-
for _, r := range testResults {
68-
failed += w.readResult(r)
69-
}
70-
}
71-
7249
if failed > 0 {
7350
w.printFailures(testResults)
7451
}
@@ -82,12 +59,10 @@ func (w *OutputWriter) Start(results <-chan runtime.TestResult) bool {
8259
w.fprintf(au.Green(summary))
8360
}
8461

85-
w.printFileErrors(fileErrors)
86-
8762
return failed == 0
8863
}
8964

90-
func (w *OutputWriter) readResult(r runtime.TestResult) int {
65+
func (w *OutputWriter) printResult(r runtime.TestResult) int {
9166
if !r.ValidationResult.Success {
9267
str := fmt.Sprintf("✗ [%s] %s", r.Node, r.TestCase.Title)
9368
str = w.addFile(str, r)
@@ -140,18 +115,6 @@ func (w *OutputWriter) addTries(s string, r runtime.TestResult) string {
140115
return s
141116
}
142117

143-
func (w *OutputWriter) printFileErrors(errors []error) {
144-
if len(errors) <= 0 {
145-
return
146-
}
147-
148-
w.fprintf("")
149-
w.fprintf("File Errors:")
150-
for _, e := range errors {
151-
w.fprintf(e)
152-
}
153-
}
154-
155118
func (w *OutputWriter) fprintf(a ...interface{}) {
156119
if _, err := fmt.Fprintln(w.out, a...); err != nil {
157120
log.Fatal(err)

pkg/output/cli_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func Test_NewCliOutput(t *testing.T) {
15-
got := NewCliOutput(true, true)
15+
got := NewCliOutput(true)
1616
assert.IsType(t, OutputWriter{}, got)
1717
}
1818

@@ -25,7 +25,7 @@ func Test_Start(t *testing.T) {
2525
go func() {
2626
defer wg.Done()
2727

28-
writer := OutputWriter{out: &buf, order: true}
28+
writer := OutputWriter{out: &buf}
2929
got := writer.Start(results)
3030

3131
assert.False(t, got)
@@ -94,11 +94,6 @@ func Test_Start(t *testing.T) {
9494
Tries: 2,
9595
}
9696

97-
results <- runtime.TestResult{
98-
FileName: "MySweetFile",
99-
FileError: fmt.Errorf("Some file error message"),
100-
}
101-
10297
close(results)
10398
wg.Wait()
10499

@@ -109,7 +104,6 @@ func Test_Start(t *testing.T) {
109104
assert.Contains(t, output, "✗ [local] 'Invalid command' could not be executed with error message")
110105
assert.Contains(t, output, "✗ [ssh-host1] 'Failed test on stderr', on property 'Stderr'")
111106
assert.Contains(t, output, "Some error message")
112-
assert.Contains(t, output, "Some file error message")
113107
}
114108

115109
func Test_SuccessSuite(t *testing.T) {

pkg/runtime/runtime.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ type TestResult struct {
134134
Node string
135135
Error error
136136
FileName string
137-
FileError error
138137
}
139138

140139
// Start starts the given test suite and executes all tests

0 commit comments

Comments
 (0)