-
Notifications
You must be signed in to change notification settings - Fork 10
/
util_test.go
48 lines (39 loc) · 1.05 KB
/
util_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 luks
import (
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestIsPowerOf2(t *testing.T) {
valid := []uint{1, 2, 4, 1 << 3, 1 << 8, 1 << 24}
invalid := []uint{3, 5, 9, 323, 34322, 6521212322}
for _, v := range valid {
require.True(t, isPowerOfTwo(v))
}
for _, v := range invalid {
require.False(t, isPowerOfTwo(v))
}
}
func TestRundup(t *testing.T) {
require.Equal(t, 0, roundUp(0, 8))
require.Equal(t, 8, roundUp(1, 8))
}
func TestFromNulEndedSlice(t *testing.T) {
check := func(input []byte, expected string) {
str := fixedArrayToString(input)
require.Equal(t, expected, str)
}
check([]byte{}, "")
check([]byte{'r'}, "r")
check([]byte{'h', 'e', 'l', 'l', 'o', ',', ' '}, "hello, ")
check([]byte{'h', '\x00', 'l', 'l', 'o', ',', ' '}, "h")
check([]byte{'\x00'}, "")
}
func blkidUUID(filename string) (string, error) {
cmdOut, err := exec.Command("blkid", "-s", "UUID", "-o", "value", filename).CombinedOutput()
if err != nil {
return "", err
}
return strings.Trim(string(cmdOut), "\n"), nil
}