-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_io_test.go
48 lines (36 loc) · 1.15 KB
/
file_io_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
package main
import (
"testing"
"reflect"
)
func TestReadEnvFile(t *testing.T) {
actual := ReadEnvFile("./testdata/envfile")
expected := []string{"# test", `TEST_1='test_1 val'`, "", `TEST_2='test2 val'`, ""}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("not equal slice")
}
}
func TestWriteEnvFile(t *testing.T) {
texts := ReadEnvFile("./testdata/envfile")
WriteEnvFile("./testdata/write_test_envfile", texts)
actual := ReadEnvFile("./testdata/envfile")
expected := ReadEnvFile("./testdata/write_test_envfile")
if !reflect.DeepEqual(actual, expected) {
t.Errorf("not equal slice")
}
}
func TestIsLastLineEmpty(t *testing.T) {
actual := IsLastLineEmpty("./testdata/envfile")
expected := true
if actual != expected {
t.Errorf("Last line is empty but IsLastLineEmpty returned false")
}
}
func TestAppendLineToFile(t *testing.T) {
AppendLineToFile("./testdata/envfile-append", `APPEND='append val'`)
actual := ReadEnvFile("./testdata/envfile-append")
expected := ReadEnvFile("./testdata/envfile-append.expected")
if !reflect.DeepEqual(actual, expected) {
t.Errorf("failed at appending line to file")
}
}