@@ -7,19 +7,13 @@ import (
77 "github.com/port-labs/terraform-provider-port-labs/v2/internal/cli"
88)
99
10- // TestRefreshBlueprintPermissionsStateWithNilUpdateMetadataProperties tests the bug
11- // that occurs during import when UpdateMetadataProperties is nil
1210func TestRefreshBlueprintPermissionsStateWithNilUpdateMetadataProperties (t * testing.T ) {
13- // Simulate the state during import - only ID and BlueprintIdentifier are set
14- // This mimics what happens in ImportState method
1511 state := & BlueprintPermissionsModel {
1612 ID : types .StringValue ("testBlueprint" ),
1713 BlueprintIdentifier : types .StringValue ("testBlueprint" ),
18- Entities : nil , // This is nil during import
14+ Entities : nil ,
1915 }
2016
21- // Create API response with metadata properties permissions
22- // This simulates what the Port API returns
2317 ownedByTeam := false
2418 apiResponse := & cli.BlueprintPermissions {
2519 Entities : cli.BlueprintPermissionsEntities {
@@ -58,13 +52,10 @@ func TestRefreshBlueprintPermissionsStateWithNilUpdateMetadataProperties(t *test
5852 },
5953 }
6054
61- // This should panic with the bug, but pass after the fix
6255 err := refreshBlueprintPermissionsState (state , apiResponse , "testBlueprint" )
6356 if err != nil {
6457 t .Fatalf ("refreshBlueprintPermissionsState failed: %v" , err )
6558 }
66-
67- // Verify the state was populated correctly
6859 if state .Entities == nil {
6960 t .Fatal ("Entities should not be nil after refresh" )
7061 }
@@ -81,7 +72,6 @@ func TestRefreshBlueprintPermissionsStateWithNilUpdateMetadataProperties(t *test
8172 t .Fatal ("UpdateMetadataProperties.Identifier should not be nil" )
8273 }
8374
84- // Verify the roles were set correctly
8575 if len (state .Entities .UpdateMetadataProperties .Title .Roles ) != 1 {
8676 t .Errorf ("Expected 1 role for Title, got %d" , len (state .Entities .UpdateMetadataProperties .Title .Roles ))
8777 }
@@ -91,10 +81,7 @@ func TestRefreshBlueprintPermissionsStateWithNilUpdateMetadataProperties(t *test
9181 }
9282}
9383
94- // TestRefreshBlueprintPermissionsStateWithExistingUpdateMetadataProperties tests
95- // that the function works correctly when UpdateMetadataProperties already exists
9684func TestRefreshBlueprintPermissionsStateWithExistingUpdateMetadataProperties (t * testing.T ) {
97- // Simulate a state where UpdateMetadataProperties already exists (normal update scenario)
9885 ownedByTeam := false
9986 state := & BlueprintPermissionsModel {
10087 ID : types .StringValue ("testBlueprint" ),
@@ -111,7 +98,6 @@ func TestRefreshBlueprintPermissionsStateWithExistingUpdateMetadataProperties(t
11198 },
11299 }
113100
114- // Create API response
115101 apiResponse := & cli.BlueprintPermissions {
116102 Entities : cli.BlueprintPermissionsEntities {
117103 Register : cli.BlueprintPermissionsBlock {
@@ -148,12 +134,10 @@ func TestRefreshBlueprintPermissionsStateWithExistingUpdateMetadataProperties(t
148134 t .Fatalf ("refreshBlueprintPermissionsState failed: %v" , err )
149135 }
150136
151- // Verify the state was updated correctly
152137 if state .Entities .UpdateMetadataProperties .Title == nil {
153138 t .Fatal ("UpdateMetadataProperties.Title should not be nil" )
154139 }
155140
156- // The users should be sorted according to the old order (user1 first)
157141 if len (state .Entities .UpdateMetadataProperties .Title .Users ) != 2 {
158142 t .Errorf ("Expected 2 users for Title, got %d" , len (state .Entities .UpdateMetadataProperties .Title .Users ))
159143 }
0 commit comments