<commit_before>package ranchr

import (
	"testing"
	_ "time"
)

var updatedBuilders = map[string]*builder{
	"common": {
		templateSection{
			Settings: []string{
				"ssh_wait_timeout = 300m",
			},
		},
	},
	"virtualbox-iso": {
		templateSection{
			Settings: []string{},
			Arrays: map[string]interface{}{
				"vm_settings": []string{
					"memory=4096",
				},
			},
		},
	},
}

var comparePostProcessors = map[string]*postProcessor{
	"vagrant": {
		templateSection{
			Settings: []string{
				"output = :out_dir/packer.box",
			},
			Arrays: map[string]interface{}{
				"except": []string{
					"docker",
				},
				"only": []string{
					"virtualbox-iso",
				},
			},
		},
	},
	"vagrant-cloud": {
		templateSection{
			Settings: []string{
				"access_token = getAValidTokenFrom-VagrantCloud.com",
				"box_tag = foo/bar/baz",
				"no_release = false",
				"version = 1.0.2",
			},
			Arrays: map[string]interface{}{},
		},
	},
}

var compareProvisioners = map[string]*provisioner{
	"shell": {
		templateSection{
			Settings: []string{
				"execute_command = :commands_src_dir/execute_test.command",
			},
			Arrays: map[string]interface{}{
				"scripts": []string{
					":scripts_dir/setup_test.sh",
					":scripts_dir/vagrant_test.sh",
					":scripts_dir/cleanup_test.sh",
				},
				"except": []string{
					"docker",
				},
				"only": []string{
					"virtualbox-iso",
				},
			},
		},
	},
}

func init() {
	setCommonTestData()
}

/*
func TestNewRawTemplate(t *testing.T) {
	Convey("Testing NewRawTemplate", t, func() {
		Convey("Given a request for a newRawTemplate()", func() {
			rawTpl := newRawTemplate()
			Convey("The raw template should equal--we don't test the date because it is always changeing", func() {
				if rawTpl, ShouldResemble, testRawTemplate)
			})
		})
	})
}

func TestCreatePackerTemplate(t *testing.T) {
	Convey("Given a template", t, func() {
		r := &rawTemplate{}
		r = testDistroDefaults.Templates[Ubuntu]
		Convey("Calling rawTemplate.CreatePackerTemplate() should result in", func() {
			var pTpl packerTemplate
			var err error
			pTpl, err = r.createPackerTemplate()
			if err, ShouldBeNil)
			if pTpl, ShouldNotResemble, r)
		})
	})
}
*/

/*
func TestCreateBuilders(t *testing.T) {
	Convey("Given a template", t, func() {
		r := &rawTemplate{}
		r = testDistroDefaults.Templates[Ubuntu]
		var bldrs []interface{}
		var vars map[string]interface{}
		var err error
		Convey("Given a call to createBuilders", func() {
			Convey("Given a valid Builder Type", func() {
				//first merge the variables so that create builders will work
				r.mergeVariables()
				bldrs, vars, err = r.createBuilders()
				if err, ShouldBeNil)
				if vars, ShouldBeNil)
				if bldrs, ShouldNotResemble, r)
			})
			Convey("Given an unsupported Builder Types", func() {
				r.BuilderTypes[0] = "unsupported"
				bldrs, vars, err = r.createBuilders()
				if err.Error() != "The requested builder, 'unsupported', is not supported by Rancher")
				if vars, ShouldBeNil)
				if bldrs, ShouldBeNil)
			})
			Convey("Given no Builder Types", func() {
				r.BuilderTypes = nil
				bldrs, vars, err = r.createBuilders()
				if err.Error() != "rawTemplate.createBuilders: no builder types were configured, unable to create builders")
				if vars, ShouldBeNil)
				if bldrs, ShouldBeNil)
			})

		})
	})
}
*/

func TestReplaceVariables(t *testing.T) {
	r := newRawTemplate()
	r.varVals = map[string]string{
		":arch":            "amd64",
		":command_src_dir": ":src_dir/commands",
		":http_dir":        "http",
		":http_src_dir":    ":src_dir/http",
		":image":           "server",
		":name":            ":distro-:release:-:image-:arch",
		":out_dir":         "../test_files/out/:distro",
		":release":         "14.04",
		":scripts_dir":     "scripts",
		":scripts_src_dir": ":src_dir/scripts",
		":src_dir":         "../test_files/src/:distro",
		":distro":          "ubuntu",
	}
	r.delim = ":"
	s := r.replaceVariables("../test_files/src/:distro")
	if s != "../test_files/src/ubuntu" {
		t.Errorf("Expected \"../test_files/src/ubuntu\", got %q", s)
	}
	s = r.replaceVariables("../test_files/src/:distro/command")
	if s != "../test_files/src/ubuntu/command" {
		t.Errorf("Expected \"../test_files/src/ubuntu/command\", got %q", s)
	}
	s = r.replaceVariables("http")
	if s != "http" {
		t.Errorf("Expected \"http\", got %q", s)
	}
	s = r.replaceVariables("../test_files/out/:distro")
	if s != "../test_files/out/ubuntu" {
		t.Errorf("Expected \"../test_files/out/ubuntu\", got %q", s)
	}
}

func TestRawTemplateVariableSection(t *testing.T) {
	r := newRawTemplate()
	res, err := r.variableSection()
	if err != nil {
		t.Errorf("Expected error to be nil, got %q", err.Error())
	} else {
		if len(res) != 0 {
			t.Errorf("Expected an empty map, got %+v", res)
		}
	}
}

/*
func TestRawTemplateSetDefaults(t *testing.T) {<commit_msg>elide variableSection method as it didn't do anything-was a placeholder<commit_after>package ranchr

import (
	"testing"
	_ "time"
)

var updatedBuilders = map[string]*builder{
	"common": {
		templateSection{
			Settings: []string{
				"ssh_wait_timeout = 300m",
			},
		},
	},
	"virtualbox-iso": {
		templateSection{
			Settings: []string{},
			Arrays: map[string]interface{}{
				"vm_settings": []string{
					"memory=4096",
				},
			},
		},
	},
}

var comparePostProcessors = map[string]*postProcessor{
	"vagrant": {
		templateSection{
			Settings: []string{
				"output = :out_dir/packer.box",
			},
			Arrays: map[string]interface{}{
				"except": []string{
					"docker",
				},
				"only": []string{
					"virtualbox-iso",
				},
			},
		},
	},
	"vagrant-cloud": {
		templateSection{
			Settings: []string{
				"access_token = getAValidTokenFrom-VagrantCloud.com",
				"box_tag = foo/bar/baz",
				"no_release = false",
				"version = 1.0.2",
			},
			Arrays: map[string]interface{}{},
		},
	},
}

var compareProvisioners = map[string]*provisioner{
	"shell": {
		templateSection{
			Settings: []string{
				"execute_command = :commands_src_dir/execute_test.command",
			},
			Arrays: map[string]interface{}{
				"scripts": []string{
					":scripts_dir/setup_test.sh",
					":scripts_dir/vagrant_test.sh",
					":scripts_dir/cleanup_test.sh",
				},
				"except": []string{
					"docker",
				},
				"only": []string{
					"virtualbox-iso",
				},
			},
		},
	},
}

func init() {
	setCommonTestData()
}

/*
func TestNewRawTemplate(t *testing.T) {
	Convey("Testing NewRawTemplate", t, func() {
		Convey("Given a request for a newRawTemplate()", func() {
			rawTpl := newRawTemplate()
			Convey("The raw template should equal--we don't test the date because it is always changeing", func() {
				if rawTpl, ShouldResemble, testRawTemplate)
			})
		})
	})
}

func TestCreatePackerTemplate(t *testing.T) {
	Convey("Given a template", t, func() {
		r := &rawTemplate{}
		r = testDistroDefaults.Templates[Ubuntu]
		Convey("Calling rawTemplate.CreatePackerTemplate() should result in", func() {
			var pTpl packerTemplate
			var err error
			pTpl, err = r.createPackerTemplate()
			if err, ShouldBeNil)
			if pTpl, ShouldNotResemble, r)
		})
	})
}
*/

/*
func TestCreateBuilders(t *testing.T) {
	Convey("Given a template", t, func() {
		r := &rawTemplate{}
		r = testDistroDefaults.Templates[Ubuntu]
		var bldrs []interface{}
		var vars map[string]interface{}
		var err error
		Convey("Given a call to createBuilders", func() {
			Convey("Given a valid Builder Type", func() {
				//first merge the variables so that create builders will work
				r.mergeVariables()
				bldrs, vars, err = r.createBuilders()
				if err, ShouldBeNil)
				if vars, ShouldBeNil)
				if bldrs, ShouldNotResemble, r)
			})
			Convey("Given an unsupported Builder Types", func() {
				r.BuilderTypes[0] = "unsupported"
				bldrs, vars, err = r.createBuilders()
				if err.Error() != "The requested builder, 'unsupported', is not supported by Rancher")
				if vars, ShouldBeNil)
				if bldrs, ShouldBeNil)
			})
			Convey("Given no Builder Types", func() {
				r.BuilderTypes = nil
				bldrs, vars, err = r.createBuilders()
				if err.Error() != "rawTemplate.createBuilders: no builder types were configured, unable to create builders")
				if vars, ShouldBeNil)
				if bldrs, ShouldBeNil)
			})

		})
	})
}
*/

func TestReplaceVariables(t *testing.T) {
	r := newRawTemplate()
	r.varVals = map[string]string{
		":arch":            "amd64",
		":command_src_dir": ":src_dir/commands",
		":http_dir":        "http",
		":http_src_dir":    ":src_dir/http",
		":image":           "server",
		":name":            ":distro-:release:-:image-:arch",
		":out_dir":         "../test_files/out/:distro",
		":release":         "14.04",
		":scripts_dir":     "scripts",
		":scripts_src_dir": ":src_dir/scripts",
		":src_dir":         "../test_files/src/:distro",
		":distro":          "ubuntu",
	}
	r.delim = ":"
	s := r.replaceVariables("../test_files/src/:distro")
	if s != "../test_files/src/ubuntu" {
		t.Errorf("Expected \"../test_files/src/ubuntu\", got %q", s)
	}
	s = r.replaceVariables("../test_files/src/:distro/command")
	if s != "../test_files/src/ubuntu/command" {
		t.Errorf("Expected \"../test_files/src/ubuntu/command\", got %q", s)
	}
	s = r.replaceVariables("http")
	if s != "http" {
		t.Errorf("Expected \"http\", got %q", s)
	}
	s = r.replaceVariables("../test_files/out/:distro")
	if s != "../test_files/out/ubuntu" {
		t.Errorf("Expected \"../test_files/out/ubuntu\", got %q", s)
	}
}

/*
func TestRawTemplateSetDefaults(t *testing.T) {
{'fraction_non_alphanumeric': 0.17278206619435338, 'fraction_numerical': 0.003700962250185048, 'mean_word_length': 3.3167503423094478, 'pattern_counts': {'":': 86, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482806', 'n_tokens_mistral': 3909, 'n_tokens_neox': 3347, 'n_words': 717}