Exemplo n.º 1
0
func TestDevicePathUnmarshalYAML(t *testing.T) {
	type in struct {
		data string
	}
	type out struct {
		device DevicePath
		err    error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{data: `"/path"`},
			out: out{device: DevicePath("/path")},
		},
		{
			in:  in{data: `"bad"`},
			out: out{device: DevicePath("bad"), err: errors.New("device path not absolute")},
		},
	}

	for i, test := range tests {
		var device DevicePath
		err := yaml.Unmarshal([]byte(test.in.data), &device)
		if !reflect.DeepEqual(test.out.err, err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
		if !reflect.DeepEqual(test.out.device, device) {
			t.Errorf("#%d: bad device: want %#v, got %#v", i, test.out.device, device)
		}
	}
}
Exemplo n.º 2
0
func TestMkfsOptionsUnmarshalYAML(t *testing.T) {
	type in struct {
		data string
	}
	type out struct {
		options MkfsOptions
		err     error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{data: `["--label=ROOT"]`},
			out: out{options: MkfsOptions([]string{"--label=ROOT"})},
		},
	}

	for i, test := range tests {
		var options MkfsOptions
		err := yaml.Unmarshal([]byte(test.in.data), &options)
		if !reflect.DeepEqual(test.out.err, err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
		if !reflect.DeepEqual(test.out.options, options) {
			t.Errorf("#%d: bad device: want %#v, got %#v", i, test.out.options, options)
		}
	}
}
Exemplo n.º 3
0
func TestFilesystemFormatUnmarshalYAML(t *testing.T) {
	type in struct {
		data string
	}
	type out struct {
		format FilesystemFormat
		err    error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{data: `"ext4"`},
			out: out{format: FilesystemFormat("ext4")},
		},
		{
			in:  in{data: `"bad"`},
			out: out{format: FilesystemFormat("bad"), err: errors.New("invalid filesystem format")},
		},
	}

	for i, test := range tests {
		var format FilesystemFormat
		err := yaml.Unmarshal([]byte(test.in.data), &format)
		if !reflect.DeepEqual(test.out.err, err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
		if !reflect.DeepEqual(test.out.format, format) {
			t.Errorf("#%d: bad device: want %#v, got %#v", i, test.out.format, format)
		}
	}
}
Exemplo n.º 4
0
func TestFilesystemUnmarshalYAML(t *testing.T) {
	type in struct {
		data string
	}
	type out struct {
		filesystem Filesystem
		err        error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{data: "device: /foo\nformat: ext4"},
			out: out{filesystem: Filesystem{Device: "/foo", Format: "ext4"}},
		},
		{
			in:  in{data: "format: ext4"},
			out: out{filesystem: Filesystem{Format: "ext4"}, err: ErrFilesystemRelativePath},
		},
	}

	for i, test := range tests {
		var filesystem Filesystem
		err := yaml.Unmarshal([]byte(test.in.data), &filesystem)
		if !reflect.DeepEqual(test.out.err, err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
		if !reflect.DeepEqual(test.out.filesystem, filesystem) {
			t.Errorf("#%d: bad filesystem: want %#v, got %#v", i, test.out.filesystem, filesystem)
		}
	}
}
Exemplo n.º 5
0
func TestNetworkdUnitNameUnmarshalYAML(t *testing.T) {
	type in struct {
		data string
	}
	type out struct {
		unit NetworkdUnitName
		err  error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{data: `"test.network"`},
			out: out{unit: NetworkdUnitName("test.network")},
		},
		{
			in:  in{data: `"test.link"`},
			out: out{unit: NetworkdUnitName("test.link")},
		},
		{
			in:  in{data: `"test.netdev"`},
			out: out{unit: NetworkdUnitName("test.netdev")},
		},
		{
			in:  in{data: `"test.blah"`},
			out: out{err: errors.New("invalid networkd unit extension")},
		},
	}

	for i, test := range tests {
		var unit NetworkdUnitName
		err := yaml.Unmarshal([]byte(test.in.data), &unit)
		if !reflect.DeepEqual(test.out.err, err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
		if err != nil {
			continue
		}

		if !reflect.DeepEqual(test.out.unit, unit) {
			t.Errorf("#%d: bad unit: want %#v, got %#v", i, test.out.unit, unit)
		}
	}
}
Exemplo n.º 6
0
func TestFileModeUnmarshalYAML(t *testing.T) {
	type in struct {
		data string
	}
	type out struct {
		mode FileMode
		err  error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{data: `0644`},
			out: out{mode: FileMode(0644)},
		},
		{
			in:  in{data: `0420`},
			out: out{mode: FileMode(0420)},
		},
		{
			in:  in{data: `017777`},
			out: out{mode: FileMode(017777), err: ErrFileIllegalMode},
		},
	}

	for i, test := range tests {
		var mode FileMode
		err := yaml.Unmarshal([]byte(test.in.data), &mode)
		if !reflect.DeepEqual(test.out.err, err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
		if !reflect.DeepEqual(test.out.mode, mode) {
			t.Errorf("#%d: bad mode: want %#o, got %#o", i, test.out.mode, mode)
		}
	}
}