Example #1
0
func TestCertsRm(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}

	for _, data := range certRmTests {
		t.Logf("Data: %+v", data)
		if !data.expectErr {
			if output, err := test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsCreateCommandName, certsCreateSubcommandName, certName, pubKeyPath, privKeyPath}); err != nil {
				t.Errorf("Error creating cert: %s - %s", err, output)
				continue
			}
		}
		args := []string{"-E", data.env, certsRmCommandName, certsRmSubcommandName}
		if len(data.name) != 0 {
			args = append(args, data.name)
		}
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}
Example #2
0
func TestCertsCreateTwice(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}
	output, err := test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsCreateCommandName, certsCreateSubcommandName, certName, pubKeyPath, privKeyPath, "-s"})
	if err != nil {
		t.Errorf("Unexpected error: %s", output)
		return
	}
	if output != certsCreateStandardOutput {
		t.Errorf("Expected: %s. Found: %s", certsCreateStandardOutput, output)
		return
	}
	output, err = test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsCreateCommandName, certsCreateSubcommandName, certName, pubKeyPath, privKeyPath, "-s"})
	if err == nil {
		t.Errorf("Expected error but no error returned: %s", output)
		return
	}
	expectedOutput := "\033[31m\033[1m[fatal] \033[0m(92003) Cert Already Exists: A Cert already exists with the given name; alter name or delete existing cert to continue.\n"
	if output != expectedOutput {
		t.Errorf("Expected: %s. Found: %s", expectedOutput, output)
		return
	}
	if output, err = test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsRmCommandName, certsRmSubcommandName, certName}); err != nil {
		t.Errorf("Unexpected err: %s", output)
		return
	}
}
Example #3
0
func TestCertsList(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}

	for _, data := range certListTests {
		t.Logf("Data: %+v", data)
		args := []string{"-E", data.env}
		args = append(args, certsListCommandName, certsListSubcommandName)
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}
Example #4
0
func TestAssociated(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		t.Fail()
	}
	for _, data := range associatedTests {
		t.Logf("Data: %+v", data)
		if err := test.ClearAssociations(); err != nil {
			t.Error(err)
			continue
		}
		if data.associateFirst {
			if err := test.SetUpAssociation(); err != nil {
				t.Error(err)
				continue
			}
		}
		r := regexp.MustCompile(data.expectedOutput)
		output, err := test.RunCommand(test.BinaryName, []string{commandName})
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if !r.MatchString(output) {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}
Example #5
0
func TestCertsCreate(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}

	for _, data := range certCreateTests {
		t.Logf("Data: %+v", data)
		args := []string{"-E", data.env, certsCreateCommandName, certsCreateSubcommandName}
		if len(data.name) != 0 {
			args = append(args, data.name)
		}
		if len(data.pubKeyPath) != 0 {
			args = append(args, data.pubKeyPath)
		}
		if len(data.privKeyPath) != 0 {
			args = append(args, data.privKeyPath)
		}
		if data.selfSigned {
			args = append(args, "-s")
		}
		if data.skipResolve {
			args = append(args, "--resolve=false")
		}
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
		if err == nil {
			if output, err = test.RunCommand(test.BinaryName, []string{"-E", data.env, certsRmCommandName, certsRmSubcommandName, certName}); err != nil {
				t.Errorf("Unexpected err: %s", output)
				return
			}
		}
	}
}
Example #6
0
func TestAssociate(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		t.Fail()
	}
	for _, data := range associateTests {
		t.Logf("Data: %+v", data)
		args := []string{commandName, data.envLabel, data.svcLabel}
		if len(data.alias) != 0 {
			args = append(args, "-a", data.alias)
		}
		expectedRemote := "catalyze"
		if len(data.remote) != 0 {
			expectedRemote = data.remote
			args = append(args, "-r", data.remote)
		}
		if data.defaultEnv {
			args = append(args, "-d")
		}

		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %v. Found: %v", data.expectedOutput, output)
			continue
		}
		output, err = test.RunCommand("git", []string{"remote", "-v"})
		if err != nil {
			t.Errorf("Unexpected error running 'git remote -v': %s", output)
			continue
		}
		if !strings.Contains(output, expectedRemote) {
			t.Errorf("Git remote not added. Expected: %s. Found %s", expectedRemote, output)
			continue
		}
	}
}
Example #7
0
func TestCertsRmNoAssociation(t *testing.T) {
	if err := test.ClearAssociations(); err != nil {
		t.Error(err)
		return
	}
	output, err := test.RunCommand(test.BinaryName, []string{certsRmCommandName, certsRmSubcommandName, certName})
	if err == nil {
		t.Errorf("Expected error but no error returned: %s", output)
		return
	}
	expectedOutput := "\033[31m\033[1m[fatal] \033[0mNo Catalyze environment has been associated. Run \"catalyze associate\" from a local git repo first\n"
	if output != expectedOutput {
		t.Errorf("Expected: %s. Found: %s", expectedOutput, output)
		return
	}
}
Example #8
0
func TestClearNoAssociation(t *testing.T) {
	if err := test.ClearAssociations(); err != nil {
		t.Error(err)
		return
	}
	output, err := test.RunCommand(test.BinaryName, []string{commandName, "--all"})
	if err != nil {
		t.Errorf("Unexpected error : %s - %s", err, output)
		return
	}
	expectedOutput := "\033[33m\033[1m[warning] \033[0mThe \"--default\" flag has been deprecated! It will be removed in a future version.\n" + standardOutput
	if output != expectedOutput {
		t.Errorf("Expected: %s. Found: %s", expectedOutput, output)
		return
	}
}
Example #9
0
func TestClear(t *testing.T) {
	for _, data := range clearTests {
		t.Logf("Data: %+v", data)
		if err := restoreSettings(); err != nil {
			t.Error(err)
			return
		}
		args := []string{"-E", data.env, commandName}
		if data.privKey {
			args = append(args, "--private-key")
		}
		if data.session {
			args = append(args, "--session")
		}
		if data.envs {
			args = append(args, "--environments")
		}
		if data.defaultEnv {
			args = append(args, "--default")
		}
		if data.pods {
			args = append(args, "--pods")
		}
		if data.all {
			args = append(args, "--all")
		}
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}