-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
39 lines (31 loc) · 876 Bytes
/
main_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
resultLines = "*3\r\n$3\r\nSET\r\n$5\r\nprice\r\n$5\r\n99.99\r\n*3\r\n$3\r\nSET\r\n$5\r\ncolor\r\n$3\r\nred\r\n*3\r\n$3\r\nSET\r\n$4\r\nunit\r\n$7\r\nCelsius\r\n"
)
var (
fileSourceLines = []string{
"SET price 99.99",
"SET color red",
"SET unit Celsius",
}
)
func TestReadLines(t *testing.T) {
lines, err := readLines("sample_source.txt")
if err != nil {
t.Error(err)
return
}
assert.Equal(t, fileSourceLines, lines, "They should be equal")
}
func TestExists(t *testing.T) {
assert.True(t, exists("./README.md"), "README.md should exist")
assert.False(t, exists("./ABCDEFG"), "This file should not exist")
}
func TestGenerateRedisScript(t *testing.T) {
var script = generateRedisScript(fileSourceLines)
assert.Equal(t, resultLines, script, "They should be equal")
}