-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_test.go
57 lines (47 loc) · 1.52 KB
/
hello_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"net/http"
"io"
)
func TestCanCallTranslateWithLol(t *testing.T) {
res, _ := Translate("lol", nil)
assert.Equal(t, "laugh out loud", res, "they should be equal")
}
func TestCanCallTranslateWithFml(t *testing.T) {
m := make(map[string]string)
res, _ := Translate("fml",m)
assert.Equal(t, "f*** my life", res, "they should be equal")
}
func TestCanCallTranslateWithNotKnown(t *testing.T) {
m := make(map[string]string)
_, error := Translate("hrh",m)
assert.NotNil(t, error)
assert.Equal(t, "hrh not found", error.Error(), "Error message isn't correct")
}
func TestCanCallTranslateWithWordList(t *testing.T) {
m := make(map[string]string)
m["ram"] = "random access memory"
res, _ := Translate("ram", m)
assert.Equal(t, "random access memory", res, "they should be equal")
}
func TestCanCallTranslateWithWordListWithMissingValue(t *testing.T) {
m := make(map[string]string)
m["ram"] = "random access memory"
_, error := Translate("bob", m)
assert.NotNil(t, error)
assert.Equal(t, "bob not found", error.Error(), "Error message isn't correct")
}
func TestCanCallTranslateUpperCaseAccronym(t *testing.T) {
m := make(map[string]string)
res, _ := Translate("FML", m)
assert.Equal(t, "f*** my life", res, "they should be equal")
}
func TestGetFromServer(t *testing.T){
resp, _ := http.Get("http://localhost:8090/?a=lol")
assert.NotNil(t, resp)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, "laugh out loud", string(body))
}