コード例 #1
0
ファイル: case.go プロジェクト: dereulenspiegel/anvil
func (t *TestCase) verify() {
	testPath := path.Join(apis.DefaultTestFolder, t.suite.Name)
	if !util.FileExists(testPath) {
		// TODO check if this makes sense. Probably state PROVSIONED is better
		t.State = VERIFIED
		return
	}
	files, err := ioutil.ReadDir(testPath)
	if err != nil {
		t.State = FAILED
		t.lastError = err
		return
	}
	fmt.Printf("%sVerifying %s%s\n", chalk.Bold, t.Name, chalk.Reset)
	for _, file := range files {
		if file.IsDir() {
			result, err := t.verifyUsingVerifier(file.Name())
			failed := false
			for _, r := range result.CaseResults {
				if !r.Success || r.ErrorMsg != "" {
					failed = true
				}
			}
			if err != nil || failed {
				t.State = FAILED
				t.lastError = err
			} else {
				t.State = VERIFIED
			}
			t.printVerifyResult(result)
		}
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: dereulenspiegel/anvil
func (v *VagrantDriver) CreateInstance(name string, options map[string]interface{}) (apis.Instance, error) {
	vagrantClient := getVagrant(name)
	if util.FileExists(path.Join(DefaultAnvilFolder, DefaultVargantSubfolder, name, "Vagrantfile")) {
		status, err := vagrantClient.Status("")
		if err != nil {
			return apis.Instance{}, err
		}
		instance, err := addSshConfig(vagrantClient, &apis.Instance{Name: name, State: statusMap[status[0].State]})
		if err != nil {
			return apis.Instance{}, err
		}
		return *instance, err
	}
	vagrantOpts := vagrant.InitOptions{}
	boxName, exists := options["box"].(string)
	if exists {
		vagrantOpts.Name = boxName
	}
	boxUrl, exists := options["url"].(string)
	if exists {
		vagrantOpts.Url = boxUrl
	}
	var err error
	err = vagrantClient.Init(vagrantOpts)
	return apis.Instance{Name: name, State: apis.CREATED}, err
}
コード例 #3
0
ファイル: main.go プロジェクト: dereulenspiegel/anvil
func (v *VagrantDriver) UpdateState(name string) (apis.Instance, error) {
	if !util.FileExists(path.Join(DefaultAnvilFolder, DefaultVargantSubfolder, name, "Vagrantfile")) {
		return apis.Instance{Name: name, State: apis.DESTROYED}, nil
	}
	vagrantClient := getVagrant(name)
	status, err := vagrantClient.Status("")
	if len(status) == 0 {
		return apis.Instance{Name: name, State: apis.DESTROYED}, nil
	}
	instance, err := addSshConfig(vagrantClient, &apis.Instance{Name: name, State: statusMap[status[0].State]})
	if err != nil {
		return apis.Instance{}, err
	}
	return *instance, err
}
コード例 #4
0
ファイル: state.go プロジェクト: dereulenspiegel/anvil
func (t *TestCase) LoadState() {
	stateFilePath := path.Join(DefaultStateFolder, fmt.Sprintf("%s_%s.yml", DefaultStatePrefix, t.Name))
	if !util.FileExists(stateFilePath) {
		return
	}
	state := &TestCase{}
	data, err := ioutil.ReadFile(stateFilePath)
	if err != nil {
		log.Fatalf("Can't read state from %s: %v", stateFilePath, err)
	}
	err = yaml.Unmarshal(data, state)
	if err != nil {
		log.Fatalf("Can't unmarshall sate: %v", err)
	}
	t.State = state.State
}