forked from ivahaev/amigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamigo_test.go
46 lines (42 loc) · 1.23 KB
/
amigo_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
package amigo
import (
"runtime"
"testing"
"time"
)
func TestAmigo(t *testing.T) {
t.Run("#New", func(t *testing.T) {
t.Run("should return pointer to a new Amigo struct with username and password filled and default host and port settings", func(t *testing.T) {
a := New(&Settings{Username: "username", Password: "secret"})
if a.settings.Username != "username" {
t.Fatal("username mismatched")
}
if a.settings.Password != "secret" {
t.Fatal("secret mismatched")
}
})
t.Run("should return pointer to a new Amigo struct with username and password filled and provided host and default port settings", func(t *testing.T) {
a := New(&Settings{Username: "username", Password: "secret", Host: "amigo"})
if a.settings.Username != "username" {
t.Fatal("username mismatched")
}
if a.settings.Password != "secret" {
t.Fatal("secret mismatched")
}
if a.settings.Host != "amigo" {
t.Fatal("host mismatched")
}
})
})
}
func TestAmigoClose(t *testing.T) {
a := New(&Settings{Username: "username", Password: "secret"})
a.Connect()
a.Close()
a.Close()
time.Sleep(time.Second * 1)
routines := runtime.NumGoroutine()
if routines > 2 {
t.Fatalf("too many go routines, expected 2 got %d", routines)
}
}