generated from pulumi/pulumi-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Refresh and destroy on resources with an out of band deletion (#154
) DeploymentSettings, Team and Webhook api client now returns nil on 404 responses so the provider treats it accordingly and recognize them as deleted resources Fix #146 <img width="1169" alt="image" src="https://github.com/pulumi/pulumi-pulumiservice/assets/5647310/9c2b49bf-ceb9-43ee-996c-3766bccc9c4b"> <img width="1162" alt="image" src="https://github.com/pulumi/pulumi-pulumiservice/assets/5647310/1ad9eb82-b5d1-4072-aec2-7a9c0d3180e5">
- Loading branch information
Showing
13 changed files
with
442 additions
and
11 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
provider/pkg/internal/pulumiapi/deployment_setting_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package pulumiapi | ||
|
||
import ( | ||
"net/http" | ||
"path" | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDeploymentSettings(t *testing.T) { | ||
|
||
orgName := "an-organization" | ||
projectName := "a-project" | ||
stackName := "a-stack" | ||
|
||
t.Run("Happy Path", func(t *testing.T) { | ||
dsValue := DeploymentSettings{ | ||
OperationContext: &OperationContext{}, | ||
GitHub: &GitHubConfiguration{}, | ||
SourceContext: &apitype.SourceContext{}, | ||
ExecutorContext: &apitype.ExecutorContext{}, | ||
} | ||
|
||
c, cleanup := startTestServer(t, testServerConfig{ | ||
ExpectedReqMethod: http.MethodGet, | ||
ExpectedReqPath: "/" + path.Join("api", "preview", orgName, projectName, stackName, "deployment", "settings"), | ||
ResponseCode: 200, | ||
ResponseBody: dsValue, | ||
}) | ||
defer cleanup() | ||
|
||
ds, err := c.GetDeploymentSettings(ctx, StackName{ | ||
OrgName: orgName, | ||
ProjectName: projectName, | ||
StackName: stackName, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, *ds, dsValue) | ||
}) | ||
|
||
t.Run("404", func(t *testing.T) { | ||
c, cleanup := startTestServer(t, testServerConfig{ | ||
ExpectedReqMethod: http.MethodGet, | ||
ExpectedReqPath: "/" + path.Join("api", "preview", orgName, projectName, stackName, "deployment", "settings"), | ||
ResponseCode: 404, | ||
ResponseBody: errorResponse{ | ||
StatusCode: 404, | ||
Message: "not found", | ||
}, | ||
}) | ||
defer cleanup() | ||
|
||
ds, err := c.GetDeploymentSettings(ctx, StackName{ | ||
OrgName: orgName, | ||
ProjectName: projectName, | ||
StackName: stackName, | ||
}) | ||
|
||
assert.Nil(t, ds, "deployment settings should be nil since error was returned") | ||
assert.Nil(t, err, "err should be nil since error was returned") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/pulumi/pulumi-pulumiservice/provider/pkg/internal/pulumiapi" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype" | ||
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type getDeploymentSettingsFunc func() (*pulumiapi.DeploymentSettings, error) | ||
|
||
type DeploymentSettingsClientMock struct { | ||
getDeploymentSettingsFunc getDeploymentSettingsFunc | ||
} | ||
|
||
func (c *DeploymentSettingsClientMock) CreateDeploymentSettings(ctx context.Context, stack pulumiapi.StackName, ds pulumiapi.DeploymentSettings) error { | ||
return nil | ||
} | ||
func (c *DeploymentSettingsClientMock) GetDeploymentSettings(ctx context.Context, stack pulumiapi.StackName) (*pulumiapi.DeploymentSettings, error) { | ||
return c.getDeploymentSettingsFunc() | ||
} | ||
func (c *DeploymentSettingsClientMock) DeleteDeploymentSettings(ctx context.Context, stack pulumiapi.StackName) error { | ||
return nil | ||
} | ||
|
||
func buildDeploymentSettingsClientMock(getDeploymentSettingsFunc getDeploymentSettingsFunc) *DeploymentSettingsClientMock { | ||
return &DeploymentSettingsClientMock{ | ||
getDeploymentSettingsFunc, | ||
} | ||
} | ||
|
||
func TestDeploymentSettings(t *testing.T) { | ||
t.Run("Read when the resource is not found", func(t *testing.T) { | ||
mockedClient := buildDeploymentSettingsClientMock( | ||
func() (*pulumiapi.DeploymentSettings, error) { return nil, nil }, | ||
) | ||
|
||
provider := PulumiServiceDeploymentSettingsResource{ | ||
client: mockedClient, | ||
} | ||
|
||
req := pulumirpc.ReadRequest{ | ||
Id: "abc/def/123", | ||
Urn: "urn:123", | ||
} | ||
|
||
resp, err := provider.Read(&req) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, resp.Id, "") | ||
assert.Nil(t, resp.Properties) | ||
}) | ||
|
||
t.Run("Read when the resource is found", func(t *testing.T) { | ||
mockedClient := buildDeploymentSettingsClientMock( | ||
func() (*pulumiapi.DeploymentSettings, error) { | ||
return &pulumiapi.DeploymentSettings{ | ||
OperationContext: &pulumiapi.OperationContext{}, | ||
GitHub: &pulumiapi.GitHubConfiguration{}, | ||
SourceContext: &apitype.SourceContext{}, | ||
ExecutorContext: &apitype.ExecutorContext{}, | ||
}, nil | ||
}, | ||
) | ||
|
||
provider := PulumiServiceDeploymentSettingsResource{ | ||
client: mockedClient, | ||
} | ||
|
||
req := pulumirpc.ReadRequest{ | ||
Id: "abc/def/123", | ||
Urn: "urn:123", | ||
} | ||
|
||
resp, err := provider.Read(&req) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, resp.Id, "abc/def/123") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.