-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathfile_helpers_test.go
103 lines (94 loc) · 1.84 KB
/
file_helpers_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright (c) F5, Inc.
*
* This source code is licensed under the Apache License, Version 2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
package files
import (
"os"
"testing"
"time"
"github.com/gogo/protobuf/types"
"github.com/stretchr/testify/assert"
)
func TestGetFileMode(t *testing.T) {
fileModeTests := []struct {
input string
expected os.FileMode
}{
{
input: "0644",
expected: os.FileMode(0o644),
},
{
input: "0",
expected: os.FileMode(0),
},
{
input: "0777",
expected: os.FileMode(0o777),
},
{
input: "0234",
expected: os.FileMode(0o234),
},
{
input: "invalid",
expected: os.FileMode(0o644),
},
}
for _, test := range fileModeTests {
result := GetFileMode(test.input)
assert.Equal(t, test.expected, result)
}
}
func TestGetPermissions(t *testing.T) {
fileModeTests := []struct {
input os.FileMode
expected string
}{
{
input: os.FileMode(0o644),
expected: "0644",
},
{
input: os.FileMode(0),
expected: "0",
},
{
input: os.FileMode(0o777),
expected: "0777",
},
{
input: os.FileMode(0o234),
expected: "0234",
},
}
for _, test := range fileModeTests {
result := GetPermissions(test.input)
assert.Equal(t, test.expected, result)
}
}
func TestTimeConvert(t *testing.T) {
fileModeTests := []struct {
input time.Time
expected *types.Timestamp
}{
{
input: time.Date(2022, 0o1, 23, 12, 0, 20, 100, &time.Location{}),
expected: &types.Timestamp{
Seconds: 1642939220,
Nanos: 100,
},
},
{
input: time.Date(-2022, 0o1, 23, 12, 0, 20, 100, &time.Location{}),
expected: types.TimestampNow(),
},
}
for _, test := range fileModeTests {
result := TimeConvert(test.input)
assert.Equal(t, test.expected.Seconds, result.Seconds)
}
}