-
Notifications
You must be signed in to change notification settings - Fork 10
/
util_linux_test.go
48 lines (39 loc) · 1.07 KB
/
util_linux_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
package fsquota
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetIDsFromUserOrGroupFile(t *testing.T) {
t.Run("FileNotFound", func(t *testing.T) {
dirName, err := ioutil.TempDir("", "fsquota-test-")
require.NoError(t, err)
defer os.RemoveAll(dirName)
ids, err := getIDsFromUserOrGroupFile(filepath.Join(dirName, "non-existent"))
assert.Nil(t, ids)
if assert.Error(t, err) {
assert.True(t, os.IsNotExist(err))
}
})
t.Run("OK", func(t *testing.T) {
dirName, err := ioutil.TempDir("", "fsquota-test-")
require.NoError(t, err)
defer os.RemoveAll(dirName)
fileData := `
# line without colon
too:few:parts
ignored:ignored:unparsable:ignored
ignored:ignored:1:ok1
ignored:ignored:2:ok2
ignored:ignored:1000:ok1000
`
fileName := filepath.Join(dirName, "ids")
require.NoError(t, ioutil.WriteFile(fileName, []byte(fileData), 0640))
ids, err := getIDsFromUserOrGroupFile(fileName)
assert.NoError(t, err)
assert.EqualValues(t, []uint32{1, 2, 1000}, ids)
})
}