File: libvirt_test.go

package info (click to toggle)
packer 1.6.6%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 32,016 kB
  • sloc: sh: 1,154; python: 619; makefile: 251; ruby: 205; xml: 97
file content (69 lines) | stat: -rw-r--r-- 2,096 bytes parent folder | download | duplicates (2)
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
package vagrant

import (
	"fmt"
	"testing"
)

func assertSizeInMegabytes(t *testing.T, size string, expected uint64) {
	actual := sizeInMegabytes(size)
	if actual != expected {
		t.Fatalf("the size `%s` was converted to `%d` but expected `%d`", size, actual, expected)
	}
}

func Test_sizeInMegabytes_WithInvalidUnitMustPanic(t *testing.T) {
	defer func() {
		if r := recover(); r == nil {
			t.Fatalf("expected a panic but got none")
		}
	}()

	sizeInMegabytes("1234x")
}

func Test_sizeInMegabytes_WithoutUnitMustDefaultToMegabytes(t *testing.T) {
	assertSizeInMegabytes(t, "1234", 1234)
}

func Test_sizeInMegabytes_WithBytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, fmt.Sprintf("%db", 1234*1024*1024), 1234)
	assertSizeInMegabytes(t, fmt.Sprintf("%dB", 1234*1024*1024), 1234)
	assertSizeInMegabytes(t, "1B", 0)
}

func Test_sizeInMegabytes_WithKiloBytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, fmt.Sprintf("%dk", 1234*1024), 1234)
	assertSizeInMegabytes(t, fmt.Sprintf("%dK", 1234*1024), 1234)
	assertSizeInMegabytes(t, "1K", 0)
}

func Test_sizeInMegabytes_WithMegabytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, "1234m", 1234)
	assertSizeInMegabytes(t, "1234M", 1234)
	assertSizeInMegabytes(t, "1M", 1)
}

func Test_sizeInMegabytes_WithGigabytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, "1234g", 1234*1024)
	assertSizeInMegabytes(t, "1234G", 1234*1024)
	assertSizeInMegabytes(t, "1G", 1*1024)
}

func Test_sizeInMegabytes_WithTerabytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, "1234t", 1234*1024*1024)
	assertSizeInMegabytes(t, "1234T", 1234*1024*1024)
	assertSizeInMegabytes(t, "1T", 1*1024*1024)
}

func Test_sizeInMegabytes_WithPetabytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, "1234p", 1234*1024*1024*1024)
	assertSizeInMegabytes(t, "1234P", 1234*1024*1024*1024)
	assertSizeInMegabytes(t, "1P", 1*1024*1024*1024)
}

func Test_sizeInMegabytes_WithExabytesUnit(t *testing.T) {
	assertSizeInMegabytes(t, "1234e", 1234*1024*1024*1024*1024)
	assertSizeInMegabytes(t, "1234E", 1234*1024*1024*1024*1024)
	assertSizeInMegabytes(t, "1E", 1*1024*1024*1024*1024)
}