forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
62 lines (50 loc) · 1.71 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"github.com/pulumi/pulumi/pkg/resource"
"github.com/pulumi/pulumi/sdk/go/pulumi"
"github.com/stretchr/testify/assert"
"testing"
)
type testMonitor struct {
CallF func(tok string, args resource.PropertyMap, provider string) (resource.PropertyMap, error)
NewResourceF func(typeToken, name string, inputs resource.PropertyMap,
provider, id string) (string, resource.PropertyMap, error)
}
func (m *testMonitor) Call(tok string, args resource.PropertyMap, provider string) (resource.PropertyMap, error) {
if m.CallF == nil {
return resource.PropertyMap{}, nil
}
return m.CallF(tok, args, provider)
}
func (m *testMonitor) NewResource(typeToken, name string, inputs resource.PropertyMap,
provider, id string) (string, resource.PropertyMap, error) {
if m.NewResourceF == nil {
return name, resource.PropertyMap{}, nil
}
return m.NewResourceF(typeToken, name, inputs, provider, id)
}
func TestCreateBucket(t *testing.T) {
bucketName := "my-bucket-unique-name"
mocks := &testMonitor{
NewResourceF: func(typeToken, name string, inputs resource.PropertyMap,
provider, id string) (string, resource.PropertyMap, error) {
assert.Equal(t, "aws:s3/bucket:Bucket", typeToken)
return id, resource.NewPropertyMapFromMap(map[string]interface{}{
"bucket": bucketName,
}), nil
},
}
err := pulumi.RunErr(func(ctx *pulumi.Context) error {
bucket, err := CreateBucket(ctx)
assert.NoError(t, err)
resultChan := make(chan string)
bucket.Bucket.ApplyT(func(val string) (string, error) {
resultChan <- val
return val, nil
})
actual := <-resultChan
assert.Equal(t, bucketName, actual)
return nil
}, pulumi.WithMocks("project", "stack", mocks))
assert.NoError(t, err)
}