-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwriter_test.go
75 lines (59 loc) · 1.2 KB
/
writer_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
72
73
74
75
package main
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestWriteToStdin(t *testing.T) {
var buf bytes.Buffer
w, err := NewWriter(&buf, templates["plaintext"])
assert.Nil(t, err)
s := []*SecretData{
&SecretData{
Path: "secrets/mysecret",
Name: "mysecret_user",
Data: "root",
},
&SecretData{
Path: "secrets/mysecret",
Name: "mysecret_password",
Data: "s3cr3t",
},
}
_ = w.Write(s...)
expected := `
export MYSECRET_USER="root"
export MYSECRET_PASSWORD="s3cr3t"`
assert.Equal(t, expected, buf.String())
}
func TestWriteToFile(t *testing.T) {
file, err := os.CreateTemp("", "test")
if err != nil {
panic(err)
}
defer os.Remove(file.Name())
w, err := NewWriter(file, templates["plaintext"])
assert.Nil(t, err)
s := []*SecretData{
&SecretData{
Path: "secrets/mysecret",
Name: "mysecret_user",
Data: "root",
},
&SecretData{
Path: "secrets/mysecret",
Name: "mysecret_password",
Data: "s3cr3t",
},
}
_ = w.Write(s...)
content, err := os.ReadFile(file.Name())
if err != nil {
panic(err)
}
expected := `
export MYSECRET_USER="root"
export MYSECRET_PASSWORD="s3cr3t"`
assert.Equal(t, expected, string(content))
}