Skip to content

Commit ad34c7f

Browse files
committed
Added a test of the git username and password settings
1 parent 5d1ebe9 commit ad34c7f

File tree

12 files changed

+188
-2
lines changed

12 files changed

+188
-2
lines changed

cmd/octoterra_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,3 +3326,59 @@ func TestSingleProjectGroupExport(t *testing.T) {
33263326
return nil
33273327
})
33283328
}
3329+
3330+
// TestProjectWithGitUsernameExport verifies that a project can be reimported with the correct git settings
3331+
func TestProjectWithGitUsernameExport(t *testing.T) {
3332+
performTest(t, func(t *testing.T, container *octopusContainer) error {
3333+
// Arrange
3334+
newSpaceId, err := arrange(t, container, "../test/terraform/39-projectgitusername", []string{
3335+
"-var=project_git_password=" + os.Getenv("GIT_CREDENTIAL"),
3336+
})
3337+
3338+
if err != nil {
3339+
return err
3340+
}
3341+
3342+
// Act
3343+
recreatedSpaceId, err := act(t, container, newSpaceId, []string{
3344+
"-var=project_test_git_password=" + os.Getenv("GIT_CREDENTIAL"),
3345+
"-var=project_test_git_base_path=.octopus/projectgitusername",
3346+
})
3347+
3348+
if err != nil {
3349+
return err
3350+
}
3351+
3352+
// Assert
3353+
octopusClient := createClient(container, recreatedSpaceId)
3354+
3355+
collection := octopus.GeneralCollection[octopus.Project]{}
3356+
err = octopusClient.GetAllResources("Projects", &collection)
3357+
3358+
if err != nil {
3359+
return err
3360+
}
3361+
3362+
resourceName := "Test"
3363+
found := false
3364+
for _, v := range collection.Items {
3365+
if v.Name == resourceName {
3366+
found = true
3367+
3368+
if v.PersistenceSettings.Credentials.Type != "UsernamePassword" {
3369+
t.Fatal("The project must be have a git credential type of \"UsernamePassword\" (was \"" + v.PersistenceSettings.Credentials.Type + "\")")
3370+
}
3371+
3372+
if v.PersistenceSettings.Credentials.Username != "mcasperson" {
3373+
t.Fatal("The project must be have a git username of \"mcasperson\" (was \"" + v.PersistenceSettings.Credentials.Username + "\")")
3374+
}
3375+
}
3376+
}
3377+
3378+
if !found {
3379+
t.Fatal("Space must have an project called \"" + resourceName + "\"")
3380+
}
3381+
3382+
return nil
3383+
})
3384+
}

internal/converters/project_converter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ func (c ProjectConverter) convertUsernamePasswordGitPersistence(project octopus.
208208

209209
return &terraform.TerraformGitUsernamePasswordPersistenceSettings{
210210
Url: project.PersistenceSettings.Url,
211-
Username: "${var." + projectName + "_git_base_path}",
211+
Username: project.PersistenceSettings.Credentials.Username,
212212
Password: "${var." + projectName + "_git_password}",
213-
BasePath: project.PersistenceSettings.BasePath,
213+
BasePath: "${var." + projectName + "_git_base_path}",
214214
DefaultBranch: project.PersistenceSettings.DefaultBranch,
215215
ProtectedBranches: project.PersistenceSettings.ProtectedBranchNamePatterns,
216216
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
terraform {
2+
required_providers {
3+
octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.10.1" }
4+
}
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "octopusdeploy" {
2+
address = "${var.octopus_server}"
3+
api_key = "${var.octopus_apikey}"
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
variable "octopus_server" {
2+
type = string
3+
nullable = false
4+
sensitive = false
5+
description = "The URL of the Octopus server e.g. https://myinstance.octopus.app."
6+
}
7+
variable "octopus_apikey" {
8+
type = string
9+
nullable = false
10+
sensitive = true
11+
description = "The API key used to access the Octopus server. See https://octopus.com/docs/octopus-rest-api/how-to-create-an-api-key for details on creating an API key."
12+
}
13+
variable "octopus_space_id" {
14+
type = string
15+
nullable = false
16+
sensitive = false
17+
description = "The space ID to populate"
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "octopusdeploy_space" "octopus_space_test" {
2+
name = "${var.octopus_space_name}"
3+
is_default = false
4+
is_task_queue_stopped = false
5+
description = "My test space"
6+
space_managers_teams = ["teams-administrators"]
7+
}
8+
9+
output "octopus_space_id" {
10+
value = octopusdeploy_space.octopus_space_test.id
11+
}
12+
13+
variable "octopus_space_name" {
14+
type = string
15+
nullable = false
16+
sensitive = false
17+
description = "The name of the new space"
18+
default = "Test"
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
terraform {
2+
required_providers {
3+
octopusdeploy = { source = "OctopusDeployLabs/octopusdeploy", version = "0.10.1" }
4+
}
5+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
data "octopusdeploy_lifecycles" "lifecycle_default_lifecycle" {
2+
ids = null
3+
partial_name = "Default Lifecycle"
4+
skip = 0
5+
take = 1
6+
}
7+
8+
9+
resource "octopusdeploy_project" "deploy_frontend_project" {
10+
auto_create_release = false
11+
default_guided_failure_mode = "EnvironmentDefault"
12+
default_to_skip_if_already_installed = false
13+
description = "Test project"
14+
discrete_channel_release = false
15+
is_disabled = false
16+
is_discrete_channel_release = false
17+
is_version_controlled = false
18+
lifecycle_id = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id
19+
name = "Test"
20+
project_group_id = octopusdeploy_project_group.project_group_test.id
21+
tenanted_deployment_participation = "Untenanted"
22+
space_id = var.octopus_space_id
23+
included_library_variable_sets = []
24+
versioning_strategy {
25+
template = "#{Octopus.Version.LastMajor}.#{Octopus.Version.LastMinor}.#{Octopus.Version.LastPatch}.#{Octopus.Version.NextRevision}"
26+
}
27+
28+
connectivity_policy {
29+
allow_deployments_to_no_targets = false
30+
exclude_unhealthy_targets = false
31+
skip_machine_behavior = "SkipUnavailableMachines"
32+
}
33+
34+
git_username_password_persistence_settings {
35+
url = "https://github.com/mcasperson/octogittest.git"
36+
username = "mcasperson"
37+
password = "${var.project_git_password}"
38+
base_path = ".octopus/projectest"
39+
default_branch = "main"
40+
protected_branches = []
41+
}
42+
}
43+
44+
variable "project_git_password" {
45+
type = string
46+
nullable = false
47+
sensitive = true
48+
description = "The git password for the project"
49+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "octopusdeploy_project_group" "project_group_test" {
2+
name = "Test"
3+
description = "Test Description"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "octopusdeploy" {
2+
address = "${var.octopus_server}"
3+
api_key = "${var.octopus_apikey}"
4+
space_id = "${var.octopus_space_id}"
5+
}

0 commit comments

Comments
 (0)