Skip to content

Commit e6e58a4

Browse files
committed
Update Check() test
1 parent 3c8048a commit e6e58a4

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

provider/pkg/provider/remote/copyController_test.go

+24-29
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
"path/filepath"
99
"testing"
1010

11+
p "github.com/pulumi/pulumi-go-provider"
1112
"github.com/pulumi/pulumi-go-provider/infer/types"
13+
1214
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
1315
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/archive"
1416
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
1517

1618
"github.com/gliderlabs/ssh"
1719
"github.com/pkg/sftp"
18-
p "github.com/pulumi/pulumi-go-provider"
1920
"github.com/stretchr/testify/assert"
2021
"github.com/stretchr/testify/require"
2122
xssh "golang.org/x/crypto/ssh"
@@ -147,73 +148,67 @@ func TestCopyDirectories(t *testing.T) {
147148
}
148149

149150
func TestCheck(t *testing.T) {
150-
host := "host"
151-
validConnection := &Connection{
152-
connectionBase: connectionBase{Host: &host},
153-
}
154-
155-
copy := &CopyToRemote{}
156-
157-
makeNewInput := func(asset *asset.Asset, archive *archive.Archive) CopyToRemoteInputs {
158-
aa := types.AssetOrArchive{}
159-
if asset != nil {
160-
aa.Asset = asset
161-
} else if archive != nil {
162-
aa.Archive = archive
163-
}
164-
return CopyToRemoteInputs{
165-
Connection: validConnection,
166-
Source: aa,
167-
RemotePath: "path/to/remote",
151+
makeNewInput := func(asset *asset.Asset, archive *archive.Archive) resource.PropertyMap {
152+
m := map[string]any{
153+
"connection": map[string]any{
154+
"host": "myhost",
155+
},
156+
"remotePath": "path/to/remote",
157+
// AssetOrArchive has special handling in pulumi-go-provider and is kept as a primitive.
158+
"source": types.AssetOrArchive{
159+
Asset: asset,
160+
Archive: archive,
161+
},
168162
}
163+
return resource.NewPropertyMapFromMap(m)
169164
}
170165

171-
checkNoError := func(news CopyToRemoteInputs) []p.CheckFailure {
172-
newsRaw := resource.NewPropertyMap(news)
173-
_, failures, err := copy.Check(context.Background(), "urn", nil, newsRaw)
166+
check := func(news resource.PropertyMap) []p.CheckFailure {
167+
copy := &CopyToRemote{}
168+
_, failures, err := copy.Check(context.Background(), "urn", nil, news)
174169
require.NoError(t, err)
175170
return failures
176171
}
177172

178173
t.Run("happy path, asset", func(t *testing.T) {
179174
news := makeNewInput(&asset.Asset{Path: "path/to/file"}, nil)
180-
failures := checkNoError(news)
175+
failures := check(news)
181176
assert.Empty(t, failures)
182177
})
183178

184179
t.Run("happy path, archive", func(t *testing.T) {
185180
news := makeNewInput(nil, &archive.Archive{Path: "path/to/file"})
186-
failures := checkNoError(news)
181+
failures := check(news)
187182
assert.Empty(t, failures)
188183
})
189184

190185
t.Run("asset or archive, not both", func(t *testing.T) {
191186
news := makeNewInput(&asset.Asset{Path: "path/to/file"}, &archive.Archive{Path: "path/to/file"})
192-
failures := checkNoError(news)
187+
failures := check(news)
193188
assert.Len(t, failures, 1)
194189
})
195190

196191
t.Run("need asset or archive", func(t *testing.T) {
197192
news := makeNewInput(nil, nil)
198-
failures := checkNoError(news)
193+
failures := check(news)
199194
assert.Len(t, failures, 1)
200195
})
201196

202197
t.Run("asset must be path-based", func(t *testing.T) {
203198
news := makeNewInput(&asset.Asset{URI: "http://example.com"}, nil)
204-
failures := checkNoError(news)
199+
failures := check(news)
205200
assert.Len(t, failures, 1)
206201
})
207202

208203
t.Run("archive must be path-based", func(t *testing.T) {
209204
news := makeNewInput(nil, &archive.Archive{URI: "http://example.com"})
210-
failures := checkNoError(news)
205+
failures := check(news)
211206
assert.Len(t, failures, 1)
212207
})
213208

214209
t.Run("can diagnose multiple issues", func(t *testing.T) {
215210
news := makeNewInput(&asset.Asset{URI: "http://example.com"}, &archive.Archive{URI: "http://example.com"})
216-
failures := checkNoError(news)
211+
failures := check(news)
217212
assert.Len(t, failures, 3)
218213
})
219214
}

0 commit comments

Comments
 (0)