@@ -37,6 +37,7 @@ import (
37
37
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
38
38
shimschema "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/schema"
39
39
shimv1 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v1"
40
+ "github.com/spf13/afero"
40
41
)
41
42
42
43
func Test_DeprecationMessage (t * testing.T ) {
@@ -669,3 +670,43 @@ func TestGetUniqueLeafDocsDescriptions(t *testing.T) {
669
670
})
670
671
}
671
672
}
673
+
674
+ func Test_aferoDirToBytesMap (t * testing.T ) {
675
+ t .Parallel ()
676
+ fs := afero .NewMemMapFs ()
677
+
678
+ t .Run ("happy path" , func (t * testing.T ) {
679
+ err := afero .WriteFile (fs , "/root/file1.txt" , []byte ("hello world" ), 0o600 )
680
+ require .NoError (t , err )
681
+ err = afero .WriteFile (fs , "/root/dir1/file2.txt" , []byte ("foo bar" ), 0o600 )
682
+ require .NoError (t , err )
683
+ err = afero .WriteFile (fs , "/root/dir1/file3.txt" , []byte ("baz" ), 0o600 )
684
+ require .NoError (t , err )
685
+ err = afero .WriteFile (fs , "/root/dir2/file4.txt" , []byte ("qux" ), 0o600 )
686
+ require .NoError (t , err )
687
+
688
+ result , err := aferoDirToBytesMap (fs , "/root" )
689
+ require .NoError (t , err )
690
+
691
+ expected := map [string ][]byte {
692
+ "file1.txt" : []byte ("hello world" ),
693
+ "dir1/file2.txt" : []byte ("foo bar" ),
694
+ "dir1/file3.txt" : []byte ("baz" ),
695
+ "dir2/file4.txt" : []byte ("qux" ),
696
+ }
697
+ require .Equal (t , expected , result )
698
+ })
699
+
700
+ t .Run ("empty directory" , func (t * testing.T ) {
701
+ err := afero .WriteFile (fs , "/emptydir/.keep" , []byte {}, 0o600 )
702
+ require .NoError (t , err )
703
+ res , err := aferoDirToBytesMap (fs , "/emptydir" )
704
+ require .NoError (t , err )
705
+ require .Equal (t , map [string ][]byte {".keep" : {}}, res )
706
+ })
707
+
708
+ t .Run ("non-existent directory" , func (t * testing.T ) {
709
+ _ , err := aferoDirToBytesMap (fs , "/doesnotexist" )
710
+ require .Error (t , err , "file does not exist" )
711
+ })
712
+ }
0 commit comments