-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsera_test.go
More file actions
51 lines (42 loc) · 1.01 KB
/
sera_test.go
File metadata and controls
51 lines (42 loc) · 1.01 KB
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
package main
import (
"flag"
"os"
"testing"
"time"
)
func TestTimeoutArgWorks(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{"sera", "10", "ls"}
flag.CommandLine.Parse(os.Args[1:])
expected := time.Second * 10
var actual time.Duration
timeoutArg(&actual)
if actual != expected {
t.Errorf("got '%v', expected '%v'", actual, expected)
}
}
func TestTimeoutArgFailsOnNonInt(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{"sera", "fail", "ls"}
flag.CommandLine.Parse(os.Args[1:])
expected := time.Duration(0)
var actual time.Duration
err := timeoutArg(&actual)
if err == nil {
t.Errorf("expected error")
}
if actual != expected {
t.Errorf("got '%v', expected '%v'", actual, expected)
}
}
func TestMd5Generation(t *testing.T) {
input := "ls -ltra"
expected := "5373fa7de6f7dd54052abf86b3a53da4"
actual := md5Hash(input)
if actual != expected {
t.Errorf("got '%s', expected '%v'", actual, expected)
}
}