-
Notifications
You must be signed in to change notification settings - Fork 14
/
main_test.go
71 lines (52 loc) · 1.02 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"os"
"testing"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
)
const dotEnvFile = `
# COMMENT 1
KEY1=VALUE1
KEY2="VALUE2"
# COMMENT 2
KEY3=VALUE3
# COMMENT 3
KEY4=VALUE4
`
const dotEnvExampleFile = `
# COMMENT 3
KEY4=
# COMMENT 2
KEY3=EXAMPLEVALUE
`
const dotEnvExpected = `
# COMMENT 1
KEY1=
KEY2=
# COMMENT 2
KEY3=EXAMPLEVALUE
# COMMENT 3
KEY4=
`
func init() {
envFilePath = ".env"
exampleFilePath = ".env.example"
}
func TestRun(t *testing.T) {
fs = afero.NewMemMapFs()
err := afero.WriteFile(fs, envFilePath, []byte(dotEnvFile), os.ModePerm)
assert.Nil(t, err)
err = afero.WriteFile(fs, exampleFilePath, []byte(dotEnvExampleFile), os.ModePerm)
assert.Nil(t, err)
err = run(nil, nil)
assert.Nil(t, err)
fileContent, err := afero.ReadFile(fs, exampleFilePath)
assert.Nil(t, err)
assert.Equal(t, dotEnvExpected, string(fileContent), "they should be equal")
}
func TestWithoutEnvFile(t *testing.T) {
fs = afero.NewMemMapFs()
err := run(nil, nil)
assert.NotNil(t, err)
}