Skip to content

Commit ac313c5

Browse files
committed
Move withcontext test to only run on linux as the sleep command is a unix command
1 parent 2be09d1 commit ac313c5

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

command_linux_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package cmd
22

33
import (
44
"bytes"
5-
"github.com/stretchr/testify/assert"
5+
"context"
66
"io/ioutil"
77
"os"
88
"strings"
99
"testing"
1010
"time"
11+
12+
"github.com/stretchr/testify/assert"
1113
)
1214

1315
func TestCommand_ExecuteStderr(t *testing.T) {
@@ -138,3 +140,19 @@ func TestWithEnvironmentVariables(t *testing.T) {
138140

139141
assertEqualWithLineBreak(t, "value", c.Stdout())
140142
}
143+
144+
func TestCommand_WithContext(t *testing.T) {
145+
// ensure legacy timeout is honored
146+
cmd := NewCommand("sleep 3;", WithTimeout(1*time.Second))
147+
err := cmd.Execute()
148+
assert.NotNil(t, err)
149+
assert.Equal(t, "Command timed out after 1s", err.Error())
150+
151+
// set context timeout to 2 seconds to ensure
152+
// context takes precedence over timeout
153+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
154+
defer cancel()
155+
err = cmd.ExecuteContext(ctx)
156+
assert.NotNil(t, err)
157+
assert.Equal(t, "context deadline exceeded", err.Error())
158+
}

command_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"bytes"
5-
"context"
65
"fmt"
76
"os"
87
"runtime"
@@ -131,19 +130,3 @@ func TestCommand_SetOptions(t *testing.T) {
131130
assert.Equal(t, time.Duration(1000000000), c.Timeout)
132131
assertEqualWithLineBreak(t, "test", writer.String())
133132
}
134-
135-
func TestCommand_WithContext(t *testing.T) {
136-
// ensure legacy timeout is honored
137-
cmd := NewCommand("sleep 3;", WithTimeout(1*time.Second))
138-
err := cmd.Execute()
139-
assert.NotNil(t, err)
140-
assert.Equal(t, "Command timed out after 1s", err.Error())
141-
142-
// set context timeout to 2 seconds to ensure
143-
// context takes precedence over timeout
144-
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
145-
defer cancel()
146-
err = cmd.ExecuteContext(ctx)
147-
assert.NotNil(t, err)
148-
assert.Equal(t, "context deadline exceeded", err.Error())
149-
}

0 commit comments

Comments
 (0)