Skip to content

Commit

Permalink
wip test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyobe committed Dec 7, 2024
1 parent 26c60a9 commit 37e06b3
Showing 1 changed file with 94 additions and 14 deletions.
108 changes: 94 additions & 14 deletions examples/examples_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
package examples

import (
"io"
"os"
"path"
"strings"
"testing"

"github.com/google/uuid"
"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"io"
"os"
"path"
"strings"
"testing"
)

type Resource struct {
Type string `yaml:"type"`
Properties map[string]interface{} `yaml:"properties"`
Options map[string]interface{} `yaml:"options"`
}
type YamlProgram struct {
Name string `yaml:"name"`
Expand Down Expand Up @@ -248,14 +248,94 @@ func TestYamlWebhookExample(t *testing.T) {
}

func TestYamlSchedulesExample(t *testing.T) {
cwd := getCwd(t)
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(cwd, ".", "yaml-schedules"),
StackName: "test-stack-" + digits,
Config: map[string]string{
"digits": digits,
},

t.Run("Yaml Schedules Example", func(t *testing.T) {
cwd := getCwd(t)
digits := generateRandomFiveDigits()
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: path.Join(cwd, ".", "yaml-schedules"),
StackName: "test-stack-" + digits,
Config: map[string]string{
"digits": digits,
},
})
})

t.Run("Schedules are replaced on timestamp update", func(t *testing.T) {
tmpdir := writePulumiYaml(t, YamlProgram{
Name: "yaml-schedule-reschedule",
Runtime: "yaml",
Resources: map[string]Resource{
"settings": {
Type: "pulumiservice:DeploymentSettings",
Properties: {
"organization": ServiceProviderTestOrg,
"project": "${pulumi.project}",
"stack": "${pulumi.stack}",
"sourceContext": map[string]any{
"git": map[string]any{
"repoUrl": "https://github.com/example.git",
"branch": "refs/heads/main",
},
},
},
},
"deployment-schedule": {
Type: "pulumiservice:DeploymentSchedule",
Properties: {
"organization": ServiceProviderTestOrg,
"project": "${pulumi.project}",
"stack": "${pulumi.stack}",
"timestamp": "fn::timestamp",
"pulumiOperation": "refresh",
},
Options: {
"dependsOn": []string{"${settings}"},
},
},
"ttl-schedule": {
Type: "pulumiservice:TtlSchedule",
Properties: {
"organization": ServiceProviderTestOrg,
"project": "${pulumi.project}",
"stack": "${pulumi.stack}",
"timestamp": "fn::timestamp",
"deleteAfterDestroy": false,
},
Options: {
"dependsOn": []string{"${settings}"},
},
},
},
})

first := &strings.Builder{}
firstOut := io.MultiWriter(os.Stdout, first)

second := &strings.Builder{}
secondOut := io.MultiWriter(os.Stdout, second)

integration.ProgramTest(t, &integration.ProgramTestOptions{
StackName: "test-stack-" + generateRandomFiveDigits(),
Quick: true,
Dir: tmpdir,
Stdout: firstOut,
EditDirs: []integration.EditDir{
{
Dir: tmpdir,
Stdout: secondOut,
ExpectFailure: false,
},
},
})

t.Fail()

//// ensure first run's output printed an error that user was not found
//assert.Contains(t, first.String(), "User 'not-found-user' not found")
//
//// ensure second run's output showed that schedules were replaced due to timestamp update
//assert.Contains(t, second.String(), "[diff: ~timestamp]")
})
}

Expand Down

0 comments on commit 37e06b3

Please sign in to comment.