File: mount_test.go

package info (click to toggle)
golang-github-d-tux-go-fstab 0.0.0%2Bgit.2014.12.04.eb4090f265-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 80 kB
  • sloc: makefile: 11
file content (82 lines) | stat: -rw-r--r-- 1,419 bytes parent folder | download
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
package fstab

import (
	"strings"
	"testing"
)

var successfulParseLineExpectations map[string]Mount = map[string]Mount{
	"/dev/sda / ext4 defaults 1 2": Mount{
		"/dev/sda",
		"/",
		"ext4",
		map[string]string{
			"defaults": "",
		},
		1,
		2,
	},

	"UUID=homer / ext4 rw,uid=0": Mount{
		"UUID=homer",
		"/",
		"ext4",
		map[string]string{
			"uid": "0",
			"rw":  "",
		},
		0,
		0,
	},
}

var successfulMountStringExpectations map[string]Mount = map[string]Mount{
	"/dev/sda / ext4 defaults 1 2": Mount{
		"/dev/sda",
		"/",
		"ext4",
		map[string]string{
			"defaults": "",
		},
		1,
		2,
	},

	"UUID=homer / ext4 uid=0 0 0": Mount{
		"UUID=homer",
		"/",
		"ext4",
		map[string]string{
			"uid": "0",
		},
		0,
		0,
	},
}

func TestParseLine(t *testing.T) {
	for line, expectation := range successfulParseLineExpectations {
		mount, err := ParseLine(line)
		if nil != err {
			t.Errorf("Unexpected parse error while parsing '%s': %s", line, err)
			continue
		}

		if !mount.Equals(&expectation) {
			t.Errorf("Expected %+v, got %+v", expectation, mount)
		}

		if 0 == strings.Index(mount.Spec, "UUID") && mount.SpecType() != UUID {
			t.Errorf("Expected SpecType to be UUID")
		}
	}
}

func TestMountString(t *testing.T) {
	for expectation, mount := range successfulMountStringExpectations {
		str := mount.String()
		if str != expectation {
			t.Errorf("Expected '%s', got '%s'", expectation, str)
		}
	}
}