Skip to content

Commit

Permalink
feat: support display name in pacticipant resource
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 30, 2022
1 parent e17c606 commit 4215464
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions acceptance/pactflow/pactflow.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ resource "pact_secret" "jenkins_token" {
### Applications

resource "pact_pacticipant" "example" {
display_name = "pactflow example consumer${var.build_number}"
name = "pactflow-example-consumer${var.build_number}"
}

resource "pact_pacticipant" "AdminUI" {
display_name = "Admin UI ${var.build_number}"
name = "AdminUI${var.build_number}"
repository_url = "github.com/foo/admin"
}

resource "pact_pacticipant" "GraphQLAPI" {
display_name = "GraphQL API ${var.build_number}"
name = "GraphQLAPI${var.build_number}"
repository_url = "github.com/foo/api"
}
Expand Down
1 change: 1 addition & 0 deletions broker/pacticipant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ type Pacticipant struct {
Name string `json:"name,omitempty" pact:"example=terraform-client"`
RepositoryURL string `json:"repositoryUrl,omitempty" pact:"example=https://github.com/pactflow/terraform-provider-pact"`
MainBranch string `json:"mainBranch,omitempty" pact:"example=main"`
DisplayName string `json:"displayName,omitempty" pact:"example=terraform client"`
}
5 changes: 5 additions & 0 deletions client/client_pact_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build consumer
// +build consumer

package client
Expand Down Expand Up @@ -33,12 +34,16 @@ func TestTerraformClientPact(t *testing.T) {
pacticipant := broker.Pacticipant{
Name: "terraform-client",
RepositoryURL: "https://github.com/pactflow/new-terraform-provider-pact",
MainBranch: "Main",
DisplayName: "Terraform Client",
}

t.Run("Pacticipant", func(t *testing.T) {
pacticipant := broker.Pacticipant{
Name: "terraform-client",
RepositoryURL: "https://github.com/pactflow/terraform-provider-pact",
MainBranch: "Main",
DisplayName: "Terraform Client",
}

t.Run("CreatePacticipant", func(t *testing.T) {
Expand Down
20 changes: 15 additions & 5 deletions resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func application() *schema.Resource {
Optional: true,
Description: "Main (default) branch",
},
"display_name": {
Type: schema.TypeString,
Optional: true,
Description: "The display name of the pacticipant",
},
},
}
}
Expand All @@ -42,13 +47,15 @@ func applicationCreate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
url := d.Get("repository_url").(string)
branch := d.Get("main_branch").(string)
displayName := d.Get("display_name").(string)

log.Println("[DEBUG] creating pacticipant", name)

pacticipant := broker.Pacticipant{
Name: name,
RepositoryURL: url,
MainBranch: branch,
DisplayName: displayName,
}
_, err := client.CreatePacticipant(pacticipant)

Expand All @@ -59,6 +66,8 @@ func applicationCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(name)
d.Set("name", pacticipant.Name)
d.Set("repository_url", pacticipant.RepositoryURL)
d.Set("main_branch", pacticipant.MainBranch)
d.Set("display_name", pacticipant.DisplayName)

return nil
}
Expand All @@ -68,13 +77,15 @@ func applicationUpdate(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
url := d.Get("repository_url").(string)
branch := d.Get("main_branch").(string)
displayName := d.Get("display_name").(string)

log.Println("[DEBUG] updating pacticipant", name)

pacticipant := broker.Pacticipant{
Name: name,
RepositoryURL: url,
MainBranch: branch,
DisplayName: displayName,
}
_, err := client.UpdatePacticipant(pacticipant)

Expand All @@ -83,8 +94,10 @@ func applicationUpdate(d *schema.ResourceData, meta interface{}) error {
}

d.SetId(name)
d.Set("name", pacticipant.Name)
d.Set("repository_url", pacticipant.RepositoryURL)
d.Set("main_branch", pacticipant.MainBranch)
d.Set("display_name", pacticipant.DisplayName)

return nil
}
Expand All @@ -105,22 +118,19 @@ func applicationRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", pacticipant.Name)
d.Set("repository_url", pacticipant.RepositoryURL)
d.Set("main_branch", pacticipant.MainBranch)
d.Set("display_name", pacticipant.DisplayName)

return nil
}

func applicationDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*client.Client)
name := d.Get("name").(string)
url := d.Get("repository_url").(string)
branch := d.Get("main_branch").(string)

log.Println("[DEBUG] deleting pacticipant", name)

err := client.DeletePacticipant(broker.Pacticipant{
Name: name,
RepositoryURL: url,
MainBranch: branch,
Name: name,
})

if err != nil {
Expand Down

0 comments on commit 4215464

Please sign in to comment.