@@ -8,14 +8,15 @@ import (
8
8
"path/filepath"
9
9
"testing"
10
10
11
+ p "github.com/pulumi/pulumi-go-provider"
11
12
"github.com/pulumi/pulumi-go-provider/infer/types"
13
+
12
14
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
13
15
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/archive"
14
16
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/asset"
15
17
16
18
"github.com/gliderlabs/ssh"
17
19
"github.com/pkg/sftp"
18
- p "github.com/pulumi/pulumi-go-provider"
19
20
"github.com/stretchr/testify/assert"
20
21
"github.com/stretchr/testify/require"
21
22
xssh "golang.org/x/crypto/ssh"
@@ -147,73 +148,67 @@ func TestCopyDirectories(t *testing.T) {
147
148
}
148
149
149
150
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
+ },
168
162
}
163
+ return resource .NewPropertyMapFromMap (m )
169
164
}
170
165
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 )
174
169
require .NoError (t , err )
175
170
return failures
176
171
}
177
172
178
173
t .Run ("happy path, asset" , func (t * testing.T ) {
179
174
news := makeNewInput (& asset.Asset {Path : "path/to/file" }, nil )
180
- failures := checkNoError (news )
175
+ failures := check (news )
181
176
assert .Empty (t , failures )
182
177
})
183
178
184
179
t .Run ("happy path, archive" , func (t * testing.T ) {
185
180
news := makeNewInput (nil , & archive.Archive {Path : "path/to/file" })
186
- failures := checkNoError (news )
181
+ failures := check (news )
187
182
assert .Empty (t , failures )
188
183
})
189
184
190
185
t .Run ("asset or archive, not both" , func (t * testing.T ) {
191
186
news := makeNewInput (& asset.Asset {Path : "path/to/file" }, & archive.Archive {Path : "path/to/file" })
192
- failures := checkNoError (news )
187
+ failures := check (news )
193
188
assert .Len (t , failures , 1 )
194
189
})
195
190
196
191
t .Run ("need asset or archive" , func (t * testing.T ) {
197
192
news := makeNewInput (nil , nil )
198
- failures := checkNoError (news )
193
+ failures := check (news )
199
194
assert .Len (t , failures , 1 )
200
195
})
201
196
202
197
t .Run ("asset must be path-based" , func (t * testing.T ) {
203
198
news := makeNewInput (& asset.Asset {URI : "http://example.com" }, nil )
204
- failures := checkNoError (news )
199
+ failures := check (news )
205
200
assert .Len (t , failures , 1 )
206
201
})
207
202
208
203
t .Run ("archive must be path-based" , func (t * testing.T ) {
209
204
news := makeNewInput (nil , & archive.Archive {URI : "http://example.com" })
210
- failures := checkNoError (news )
205
+ failures := check (news )
211
206
assert .Len (t , failures , 1 )
212
207
})
213
208
214
209
t .Run ("can diagnose multiple issues" , func (t * testing.T ) {
215
210
news := makeNewInput (& asset.Asset {URI : "http://example.com" }, & archive.Archive {URI : "http://example.com" })
216
- failures := checkNoError (news )
211
+ failures := check (news )
217
212
assert .Len (t , failures , 3 )
218
213
})
219
214
}
0 commit comments