This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
version_test.go
45 lines (37 loc) · 1.3 KB
/
version_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
package main_test
import (
"strings"
"testing"
"github.com/stealthrocket/timecraft/internal/assert"
)
var version = tests{
"show the version command help with the short option": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "version", "-h")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft version\n")
assert.Equal(t, stderr, "")
},
"show the version command help with the long option": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "version", "--help")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "Usage:\ttimecraft version\n")
assert.Equal(t, stderr, "")
},
"the version starts with the prefix timecraft": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "version")
assert.Equal(t, exitCode, 0)
assert.HasPrefix(t, stdout, "timecraft ")
assert.Equal(t, stderr, "")
},
"the version number is not empty": func(t *testing.T) {
stdout, stderr, exitCode := timecraft(t, "version")
assert.Equal(t, exitCode, 0)
assert.Equal(t, stderr, "")
_, version, _ := strings.Cut(string(stdout), " ")
assert.NotEqual(t, version, "")
},
"passing an unsupported flag to the command causes an error": func(t *testing.T) {
_, _, exitCode := timecraft(t, "version", "-_")
assert.Equal(t, exitCode, 2)
},
}