Skip to content

Commit

Permalink
Fixing broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IaroslavTitov committed Jun 21, 2024
1 parent 194618c commit 69a558a
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 73 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
### Bug Fixes

### Miscellaneous

- Fixed integ tests [#328](https://github.com/pulumi/pulumi-pulumiservice/issues/328)
12 changes: 5 additions & 7 deletions examples/cs-environments/MyStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ class MyStack : Stack
public MyStack()
{
var config = new Pulumi.Config();
String yaml = """
values:
myKey1: "myValue1"
myNestedKey:
myKey2: "myValue2"
myNumber: 1
""";
String yaml = """values:
myKey1: "myValue1"
myNestedKey:
myKey2: "myValue2"
myNumber: 1""";

var environment = new Pulumi.PulumiService.Environment(
"testing-environment",
Expand Down
11 changes: 4 additions & 7 deletions examples/examples_dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

func TestDotnetTeamsExamples(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "cs-teams"),
SkipRefresh: true,
Dir: path.Join(getCwd(t), "cs-teams"),
Dependencies: []string{
"Pulumi.PulumiService",
},
Expand All @@ -22,9 +21,8 @@ func TestDotnetTeamsExamples(t *testing.T) {
func TestDotnetSchedulesExamples(t *testing.T) {
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "cs-schedules"),
StackName: "test-stack-" + digits,
SkipRefresh: true,
Dir: path.Join(getCwd(t), "cs-schedules"),
StackName: "test-stack-" + digits,
Config: map[string]string{
"digits": digits,
},
Expand All @@ -37,8 +35,7 @@ func TestDotnetSchedulesExamples(t *testing.T) {
func TestDotnetEnvironmentsExamples(t *testing.T) {
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "cs-environments"),
SkipRefresh: true,
Dir: path.Join(getCwd(t), "cs-environments"),
Config: map[string]string{
"digits": digits,
},
Expand Down
10 changes: 4 additions & 6 deletions examples/examples_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ import (

func TestGoTeamsExample(t *testing.T) {
testOpts := getGoBaseOptions(t).With(integration.ProgramTestOptions{
Verbose: true,
Dir: filepath.Join(getCwd(t), "go-teams"),
SkipRefresh: true,
Verbose: true,
Dir: filepath.Join(getCwd(t), "go-teams"),
})
integration.ProgramTest(t, &testOpts)
}

func TestGoEnvironmentsExample(t *testing.T) {
digits := generateRandomFiveDigits()
testOpts := getGoBaseOptions(t).With(integration.ProgramTestOptions{
Verbose: true,
Dir: filepath.Join(getCwd(t), "go-environments"),
SkipRefresh: true,
Verbose: true,
Dir: filepath.Join(getCwd(t), "go-environments"),
Config: map[string]string{
"digits": digits,
},
Expand Down
4 changes: 1 addition & 3 deletions examples/examples_java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
)

func TestJavaTeamsExamples(t *testing.T) {
test := getJavaBase(t, "java-teams", integration.ProgramTestOptions{
SkipRefresh: true,
})
test := getJavaBase(t, "java-teams", integration.ProgramTestOptions{})

integration.ProgramTest(t, &test)
}
Expand Down
25 changes: 10 additions & 15 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
func TestAccessTokenExample(t *testing.T) {
cwd, _ := os.Getwd()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Quick: true,
SkipRefresh: true,
Dir: path.Join(cwd, ".", "ts-access-tokens"),
Quick: true,
Dir: path.Join(cwd, ".", "ts-access-tokens"),
Dependencies: []string{
"@pulumi/pulumiservice",
},
Expand All @@ -26,9 +25,8 @@ func TestAccessTokenExample(t *testing.T) {
func TestStackTagsExample(t *testing.T) {
cwd, _ := os.Getwd()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Quick: true,
SkipRefresh: true,
Dir: path.Join(cwd, ".", "ts-stack-tags"),
Quick: true,
Dir: path.Join(cwd, ".", "ts-stack-tags"),
Dependencies: []string{
"@pulumi/pulumiservice",
},
Expand All @@ -42,9 +40,8 @@ func TestDeploymentSettingsExample(t *testing.T) {
"my_secret": "my_secret_value",
"password": "my_password",
},
Quick: true,
SkipRefresh: true,
Dir: path.Join(cwd, ".", "ts-deployment-settings"),
Quick: true,
Dir: path.Join(cwd, ".", "ts-deployment-settings"),
Dependencies: []string{
"@pulumi/pulumiservice",
},
Expand All @@ -54,9 +51,8 @@ func TestDeploymentSettingsExample(t *testing.T) {
func TestTeamStackPermissionsExample(t *testing.T) {
cwd, _ := os.Getwd()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Quick: true,
SkipRefresh: true,
Dir: path.Join(cwd, ".", "ts-team-stack-permissions"),
Quick: true,
Dir: path.Join(cwd, ".", "ts-team-stack-permissions"),
Dependencies: []string{
"@pulumi/pulumiservice",
},
Expand All @@ -66,9 +62,8 @@ func TestTeamStackPermissionsExample(t *testing.T) {
func TestTeamsExample(t *testing.T) {
cwd, _ := os.Getwd()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Quick: true,
SkipRefresh: true,
Dir: path.Join(cwd, ".", "ts-teams"),
Quick: true,
Dir: path.Join(cwd, ".", "ts-teams"),
Dependencies: []string{
"@pulumi/pulumiservice",
},
Expand Down
6 changes: 2 additions & 4 deletions examples/examples_python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (

func TestPythonTeamsExample(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "py-teams"),
SkipRefresh: true,
Dir: path.Join(getCwd(t), "py-teams"),
Dependencies: []string{
filepath.Join("..", "sdk", "python", "bin"),
},
Expand All @@ -36,8 +35,7 @@ func TestPythonDeploymentSettingsExample(t *testing.T) {
func TestPythonEnvironmentsExample(t *testing.T) {
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "py-environments"),
SkipRefresh: true,
Dir: path.Join(getCwd(t), "py-environments"),
Config: map[string]string{
"digits": digits,
},
Expand Down
5 changes: 2 additions & 3 deletions examples/examples_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ func TestYamlStackTagsExample(t *testing.T) {
require.NoError(t, err)

integration.ProgramTest(t, &integration.ProgramTestOptions{
Quick: true,
SkipRefresh: true,
Dir: tmpdir,
Quick: true,
Dir: tmpdir,
EditDirs: []integration.EditDir{
{
Dir: path.Join(cwd, ".", "yaml-stack-tags"),
Expand Down
13 changes: 7 additions & 6 deletions examples/go-environments/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
conf := config.New(ctx, "")
yaml := `values:
myKey1: "myValue1"
myNestedKey:
myKey2: "myValue2"
myNumber: 1`

environment, err := pulumiservice.NewEnvironment(ctx, "testing-environment", &pulumiservice.EnvironmentArgs{
Name: pulumi.String("testing-environment-go-" + conf.Require("digits")),
Organization: pulumi.String("service-provider-test-org"),
Yaml: pulumi.NewStringAsset(`
values:
myKey1: "myValue1"
myNestedKey:
myKey2: "myValue2"
myNumber: 1`),
Yaml: pulumi.NewStringAsset(yaml),
})
if err != nil {
return err
Expand Down
12 changes: 5 additions & 7 deletions examples/py-environments/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
"testing-environment",
organization="service-provider-test-org",
name="testing-environment-py-"+config.require('digits'),
yaml=pulumi.StringAsset("""
values:
myKey1: "myValue1"
myNestedKey:
myKey2: "myValue2"
myNumber: 1
""")
yaml=pulumi.StringAsset("""values:
myKey1: "myValue1"
myNestedKey:
myKey2: "myValue2"
myNumber: 1""")
)

# A tag that will always be placed on the latest revision of the environment
Expand Down
2 changes: 1 addition & 1 deletion provider/pkg/provider/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (at *PulumiServiceAccessTokenResource) deleteAccessToken(ctx context.Contex
}

func diffAccessTokenProperties(req *pulumirpc.DiffRequest, replaceProps []string) (*pulumirpc.DiffResponse, error) {
olds, err := plugin.UnmarshalProperties(req.GetOldInputs(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
olds, err := plugin.UnmarshalProperties(req.GetOlds(), plugin.MarshalOptions{KeepUnknowns: false, SkipNulls: true})
if err != nil {
return nil, err
}
Expand Down
12 changes: 11 additions & 1 deletion provider/pkg/provider/deployment_schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ func (st *PulumiServiceDeploymentScheduleResource) Read(req *pulumirpc.ReadReque
PulumiOperation: scheduleResponse.Definition.Request.PulumiOperation,
}

inputs, err := plugin.MarshalProperties(
input.ToPropertyMap(),
plugin.MarshalOptions{
KeepUnknowns: true,
SkipNulls: true,
},
)
if err != nil {
return nil, fmt.Errorf("failed to read DeploymentSchedule (%q): %w", req.Id, err)
}
outputProperties, err := plugin.MarshalProperties(
AddScheduleIdToPropertyMap(*scheduleID, input.ToPropertyMap()),
plugin.MarshalOptions{
Expand All @@ -366,7 +376,7 @@ func (st *PulumiServiceDeploymentScheduleResource) Read(req *pulumirpc.ReadReque
return &pulumirpc.ReadResponse{
Id: req.Id,
Properties: outputProperties,
Inputs: outputProperties,
Inputs: inputs,
}, nil
}

Expand Down
12 changes: 11 additions & 1 deletion provider/pkg/provider/drift_schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ func (st *PulumiServiceDriftScheduleResource) Read(req *pulumirpc.ReadRequest) (
AutoRemediate: scheduleResponse.Definition.Request.OperationContext.Options.AutoRemediate,
}

inputs, err := plugin.MarshalProperties(
input.ToPropertyMap(),
plugin.MarshalOptions{
KeepUnknowns: true,
SkipNulls: true,
},
)
if err != nil {
return nil, fmt.Errorf("failed to read DriftSchedule (%q): %w", req.Id, err)
}
outputProperties, err := plugin.MarshalProperties(
AddScheduleIdToPropertyMap(*scheduleID, input.ToPropertyMap()),
plugin.MarshalOptions{
Expand All @@ -211,7 +221,7 @@ func (st *PulumiServiceDriftScheduleResource) Read(req *pulumirpc.ReadRequest) (
return &pulumirpc.ReadResponse{
Id: req.Id,
Properties: outputProperties,
Inputs: outputProperties,
Inputs: inputs,
}, nil
}

Expand Down
38 changes: 28 additions & 10 deletions provider/pkg/provider/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,43 @@ func (st *PulumiServiceEnvironmentResource) Update(req *pulumirpc.UpdateRequest)
}

func (st *PulumiServiceEnvironmentResource) Read(req *pulumirpc.ReadRequest) (*pulumirpc.ReadResponse, error) {
input, err := ToPulumiServiceEnvironmentInput(req.GetProperties())
if err != nil {
return nil, err
splitID := strings.Split(req.Id, "/")
if len(splitID) < 2 {
return nil, fmt.Errorf("invalid environment id: %s", req.Id)
}
orgName := splitID[0]
envName := splitID[1]

retrievedYaml, _, revision, err := st.client.GetEnvironment(context.Background(), input.OrgName, input.EnvName, "", false)
retrievedYaml, _, revision, err := st.client.GetEnvironment(context.Background(), orgName, envName, "", false)
if err != nil {
return &pulumirpc.ReadResponse{Id: "", Properties: nil}, nil
}

input := PulumiServiceEnvironmentInput{
OrgName: orgName,
EnvName: envName,
Yaml: retrievedYaml,
}

result := PulumiServiceEnvironmentOutput{
input: PulumiServiceEnvironmentInput{
OrgName: input.OrgName,
EnvName: input.EnvName,
Yaml: retrievedYaml,
},
input: input,
revision: revision,
}

inputMap, err := input.ToPropertyMap()
if err != nil {
return nil, err
}
inputs, err := plugin.MarshalProperties(
inputMap,
plugin.MarshalOptions{
KeepSecrets: true,
},
)
if err != nil {
return nil, err
}

propertyMap, err := result.ToPropertyMap()
if err != nil {
return nil, err
Expand All @@ -292,7 +310,7 @@ func (st *PulumiServiceEnvironmentResource) Read(req *pulumirpc.ReadRequest) (*p
return &pulumirpc.ReadResponse{
Id: req.Id,
Properties: properties,
Inputs: properties,
Inputs: inputs,
}, nil
}

Expand Down
11 changes: 10 additions & 1 deletion provider/pkg/provider/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,16 @@ func (t *PulumiServiceTeamResource) Check(req *pulumirpc.CheckRequest) (*pulumir
})
}

return &pulumirpc.CheckResponse{Inputs: news, Failures: failures}, nil
if !newsMap["displayName"].HasValue() {
newsMap["displayName"] = newsMap["name"]
}

inputs, err := plugin.MarshalProperties(newsMap, plugin.MarshalOptions{KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, err
}

return &pulumirpc.CheckResponse{Inputs: inputs, Failures: failures}, nil
}

func (t *PulumiServiceTeamResource) Delete(req *pulumirpc.DeleteRequest) (*pbempty.Empty, error) {
Expand Down
4 changes: 4 additions & 0 deletions provider/pkg/provider/team_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func (t *PulumiServiceTeamAccessTokenResource) Read(req *pulumirpc.ReadRequest)
urn := req.GetId()

orgName, teamName, _, tokenId, err := splitTeamAccessTokenId(urn)
if err != nil {
return nil, err
}

// the team access token is immutable; if we get nil it got deleted, otherwise all data is the same
accessToken, err := t.client.GetTeamAccessToken(ctx, tokenId, orgName, teamName)
Expand All @@ -136,6 +139,7 @@ func (t *PulumiServiceTeamAccessTokenResource) Read(req *pulumirpc.ReadRequest)
return &pulumirpc.ReadResponse{
Id: req.GetId(),
Properties: req.GetProperties(),
Inputs: req.GetProperties(),
}, nil
}

Expand Down
Loading

0 comments on commit 69a558a

Please sign in to comment.