-
Notifications
You must be signed in to change notification settings - Fork 1
/
all_test.go
71 lines (50 loc) · 1.36 KB
/
all_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 ternary
import (
"testing"
. "github.com/otiai10/mint"
)
func TestIf(t *testing.T) {
Expect(t, If(true)).TypeOf("ternary.Condition")
}
func TestCondition_String(t *testing.T) {
message := If(true).String("Yes!", "No...")
Expect(t, message).ToBe("Yes!")
message = If(false).String("Yes!", "No...")
Expect(t, message).ToBe("No...")
}
func TestCondition_Int(t *testing.T) {
status := If(true).Int(200, 500)
Expect(t, status).ToBe(200)
status = If(false).Int(200, 500)
Expect(t, status).ToBe(500)
}
func TestCondition_Interface(t *testing.T) {
status := 200
auth := If(status == 200).Interface("ok", nil)
Expect(t, auth).ToBe("ok")
status = 403
auth = If(status == 200).Interface("ok", nil)
Expect(t, auth).ToBe(nil)
}
func TestCondition_Place(t *testing.T) {
response := map[string]interface{}{
"message": "Hello, btw!",
}
status := 200
If(status != 200).Put("error", "Failed")(response)
_, exists := response["error"]
Expect(t, exists).ToBe(false)
status = 500
If(status != 200).Put("error", "Failed")(response)
value, exists := response["error"]
Expect(t, exists).ToBe(true)
Expect(t, value).ToBe("Failed")
}
func TestZero(t *testing.T) {
port := Zero("").String("9090", "8080")
Expect(t, port).ToBe("9090")
}
func TestString(t *testing.T) {
Expect(t, String("foo")("bar")).ToBe("foo")
Expect(t, String("")("foobar")).ToBe("foobar")
}