-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgomate_test.go
52 lines (40 loc) · 1.42 KB
/
gomate_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
package gomate
import (
"fmt"
"os"
"strings"
"testing"
"github.com/rafaeljusto/redigomock"
)
func TestConnectReturnsErrorWithMessageOnFail(t *testing.T) {
redis_url := "BAD URL"
_, err := Connect(redis_url)
expected_err_msg := "Can't connect to Redis using " + redis_url
if !strings.HasPrefix(err.Error(), expected_err_msg) {
t.Errorf("Expected \"%v...\" when failing to connect to Redis using bad url, got: \"%v\"", expected_err_msg, err)
}
}
func TestConnectReturnsNoErrorOnSuccess(t *testing.T) {
redis_url := "redis://localhost:9999/7"
_, err := Connect(redis_url)
if err != nil {
t.Errorf("Expected no error, got \"%v\"", err)
}
}
func TestCleanupReturnsErrorIfCantFetchPhrases(t *testing.T) {
conn := redigomock.NewConn()
conn.Command("SMEMBERS", "gomate-index:suburb").ExpectError(fmt.Errorf("Redis fail!"))
err := Cleanup("suburb", conn)
expected_err_msg := "Failed to cleanup for suburb: Redis fail!"
if !strings.HasPrefix(err.Error(), expected_err_msg) {
t.Errorf("Expected \"%v...\" when failing to connect to Redis using bad url, got: \"%v\"", expected_err_msg, err)
}
}
func TestBulkLoad_returns_error_if_cant_cleanup(t *testing.T) {
conn := redigomock.NewConn()
conn.Command("SMEMBERS", "gomate-index:suburb").ExpectError(fmt.Errorf("Redis fail!"))
inserted, err := BulkLoad("suburb", os.Stdin, conn)
if inserted != 0 || err == nil {
t.Errorf("Expected 0 and error, got ", inserted, err)
}
}