tools_config_test.go 2.59 KB
Newer Older
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
package common

import (
	"testing"
)

func testToolsConfig() *ToolsConfig {
	return &ToolsConfig{
		ParallelsToolsFlavor:    "foo",
		ParallelsToolsGuestPath: "foo",
		ParallelsToolsMode:      "attach",
	}
}

func TestToolsConfigPrepare(t *testing.T) {
	c := testToolsConfig()
	errs := c.Prepare(testConfigTemplate(t))
	if len(errs) > 0 {
		t.Fatalf("bad err: %#v", errs)
	}
}

func TestToolsConfigPrepare_ParallelsToolsMode(t *testing.T) {
	var c *ToolsConfig
	var errs []error

	// Test default mode
	c = testToolsConfig()
	c.ParallelsToolsMode = ""
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) > 0 {
		t.Fatalf("should not have error: %#v", errs)
	}
	if c.ParallelsToolsMode != ParallelsToolsModeUpload {
		t.Errorf("bad parallels tools mode: %s", c.ParallelsToolsMode)
	}

	// Test another mode
	c = testToolsConfig()
	c.ParallelsToolsMode = "attach"
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) > 0 {
		t.Fatalf("should not have error: %#v", errs)
	}
	if c.ParallelsToolsMode != ParallelsToolsModeAttach {
		t.Fatalf("bad mode: %s", c.ParallelsToolsMode)
	}

	// Test invalid mode
	c = testToolsConfig()
	c.ParallelsToolsMode = "invalid_mode"
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) == 0 {
		t.Fatal("should have error")
	}
}

func TestToolsConfigPrepare_ParallelsToolsGuestPath(t *testing.T) {
	var c *ToolsConfig
	var errs []error

	// Test default path
	c = testToolsConfig()
	c.ParallelsToolsGuestPath = ""
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) > 0 {
		t.Fatalf("should not have error: %#v", errs)
	}
	if c.ParallelsToolsGuestPath == "" {
		t.Fatal("should not be empty")
	}

	// Test with a good one
	c = testToolsConfig()
	c.ParallelsToolsGuestPath = "foo"
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) > 0 {
		t.Fatalf("should not have error: %s", errs)
	}

	if c.ParallelsToolsGuestPath != "foo" {
		t.Fatalf("bad guest path: %s", c.ParallelsToolsGuestPath)
	}
}

func TestToolsConfigPrepare_ParallelsToolsFlavor(t *testing.T) {
	var c *ToolsConfig
	var errs []error

	// Test with a default value
	c = testToolsConfig()
	c.ParallelsToolsFlavor = ""
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) == 0 {
		t.Fatal("should have error")
	}

	// Test with an bad value
	c = testToolsConfig()
	c.ParallelsToolsMode = "attach"
	c.ParallelsToolsFlavor = ""
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) == 0 {
		t.Fatal("should have error")
	}

	// Test with a good one
	c = testToolsConfig()
	c.ParallelsToolsMode = "disable"
	c.ParallelsToolsFlavor = ""
	errs = c.Prepare(testConfigTemplate(t))
	if len(errs) > 0 {
		t.Fatalf("should not have error: %s", errs)
	}
}