-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
61 lines (51 loc) · 1.31 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
package main_test
import (
main "base64"
"io/ioutil"
"os/exec"
"testing"
"github.com/stretchr/testify/require"
)
func TestEncode(t *testing.T) {
fileNames := []string{
"test_data/test0.txt",
"test_data/test1.txt",
"test_data/cat.jpg",
}
for _, fileName := range fileNames {
// Arrange
data, err := exec.Command("base64", fileName).Output()
require.NoError(t, err)
// Without newline
expected := string(data[:len(data)-1])
// Encode の引数に渡すために、ファイルを読み込みバイト列にする。
buf, err := ioutil.ReadFile(fileName)
require.NoError(t, err)
// Act
result := main.Encode(buf)
// Assert
require.Equal(t, expected, result)
}
}
// Encode して Decode したら元に戻ることの確認。
func TestEncodeDecode(t *testing.T) {
fileNames := []string{
"test_data/test0.txt",
"test_data/test1.txt",
"test_data/cat.jpg",
}
for _, fileName := range fileNames {
// Arrange
// Encode の引数に渡すために、ファイルを読み込みバイト列にする。
buf, err := ioutil.ReadFile(fileName)
require.NoError(t, err)
// Act
encodedStr := main.Encode(buf)
t.Log(encodedStr)
t.Log([]byte(encodedStr))
decodedStr := main.Decode([]byte(encodedStr))
t.Log(decodedStr)
// Assert
require.Equal(t, buf, []byte(decodedStr))
}
}