Skip to content

Commit

Permalink
Fix panic runtime error in terraform provider for page resources (#190)
Browse files Browse the repository at this point in the history
* fix page permissions

* handle case where the response from page creation doesn't return page object

* fix user

* add userName

* add CI_USER_NAME to ci

* added =

---------

Co-authored-by: MatanGevaPort <[email protected]>
  • Loading branch information
Tankilevitch and matan84 authored Dec 5, 2024
1 parent 2adee62 commit bfce1c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
GO_VERSION: "1.18"
PORT_CLIENT_ID: ${{ secrets.PORT_CLIENT_ID }}
PORT_CLIENT_SECRET: ${{ secrets.PORT_CLIENT_SECRET }}
CI_USER_NAME: ${{ secrets.CI_USER_NAME }}

jobs:
lint:
Expand Down Expand Up @@ -47,4 +48,4 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Run dialect tests
run: make acctest PORT_CLIENT_ID=${{ secrets.PORT_CLIENT_ID }} PORT_CLIENT_SECRET=${{ secrets.PORT_CLIENT_SECRET }} PORT_BASE_URL=${{ secrets.PORT_BASE_URL }}
run: make acctest CI_USER_NAME=${{ secrets.CI_USER_NAME }} PORT_CLIENT_ID=${{ secrets.PORT_CLIENT_ID }} PORT_CLIENT_SECRET=${{ secrets.PORT_CLIENT_SECRET }} PORT_BASE_URL=${{ secrets.PORT_BASE_URL }}
9 changes: 7 additions & 2 deletions internal/cli/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ func (c *PortClient) CreatePage(ctx context.Context, page *Page) (*Page, error)
return nil, err
}
if !pb.OK {

if resp.IsSuccess() {
return nil, nil
}
return nil, fmt.Errorf("failed to create page, got: %s", resp.Body())
}
return &pb.Page, nil
// For forward compatibility, handle cases where the response body is empty when a page is created.
// The current API response body is { "ok": true, "identifier": "page_identifier" },
// but it is expected to be the page object in the future to align with other API endpoints.
if pb.Page.Identifier != "" {
return &pb.Page, nil
}
return nil, nil
}

func (c *PortClient) UpdatePage(ctx context.Context, pageId string, page *Page) (*Page, error) {
Expand Down
15 changes: 9 additions & 6 deletions port/team/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team_test
import (
"fmt"
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -36,6 +37,7 @@ func TestAccPortTeam(t *testing.T) {

func TestAccPortTeamUpdate(t *testing.T) {
teamName := utils.GenID()
userName := os.Getenv("CI_USER_NAME")
var testAccTeamConfigCreate = fmt.Sprintf(`
resource "port_team" "team" {
name = "%s"
Expand All @@ -47,8 +49,8 @@ func TestAccPortTeamUpdate(t *testing.T) {
resource "port_team" "team" {
name = "%s"
description = "Test description2"
users = ["[email protected]"]
}`, teamName)
users = ["%s"]
}`, teamName, userName)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
Expand All @@ -68,7 +70,7 @@ func TestAccPortTeamUpdate(t *testing.T) {
resource.TestCheckResourceAttr("port_team.team", "name", teamName),
resource.TestCheckResourceAttr("port_team.team", "description", "Test description2"),
resource.TestCheckResourceAttr("port_team.team", "users.#", "1"),
resource.TestCheckResourceAttr("port_team.team", "users.0", "[email protected]"),
resource.TestCheckResourceAttr("port_team.team", "users.0", userName),
),
},
},
Expand Down Expand Up @@ -115,12 +117,13 @@ func TestAccPortTeamEmptyDescription(t *testing.T) {

func TestAccPortTeamImport(t *testing.T) {
teamName := utils.GenID()
userName := os.Getenv("CI_USER_NAME")
var testAccTeamConfigCreate = fmt.Sprintf(`
resource "port_team" "team" {
name = "%s"
description = "Test description"
users = ["[email protected]"]
}`, teamName)
users = ["%s"]
}`, teamName, userName)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
Expand All @@ -132,7 +135,7 @@ func TestAccPortTeamImport(t *testing.T) {
resource.TestCheckResourceAttr("port_team.team", "name", teamName),
resource.TestCheckResourceAttr("port_team.team", "description", "Test description"),
resource.TestCheckResourceAttr("port_team.team", "users.#", "1"),
resource.TestCheckResourceAttr("port_team.team", "users.0", "[email protected]"),
resource.TestCheckResourceAttr("port_team.team", "users.0", userName),
),
},
{
Expand Down

0 comments on commit bfce1c8

Please sign in to comment.