@@ -16,7 +16,7 @@ import (
16
16
"github.com/axone-protocol/axoned/v8/x/logic/util"
17
17
)
18
18
19
- func TestSourceFile (t * testing.T ) {
19
+ func TestFilteredVFS (t * testing.T ) {
20
20
Convey ("Given test cases" , t , func () {
21
21
ctrl := gomock .NewController (t )
22
22
defer ctrl .Finish ()
@@ -74,25 +74,30 @@ func TestSourceFile(t *testing.T) {
74
74
for nc , tc := range cases {
75
75
Convey (fmt .Sprintf ("Given the test case #%d - file %s" , nc , tc .file ), func () {
76
76
Convey ("and a mocked file system" , func () {
77
- mockedFS := testutil .NewMockFS (ctrl )
78
- mockedFS .EXPECT ().Open (tc .file ).Times (lo .If (util .IsNil (tc .wantError ), 1 ).Else (0 )).
77
+ content := []byte ("42" )
78
+ mockedFS := testutil .NewMockReadFileFS (ctrl )
79
+ mockedFS .EXPECT ().Open (tc .file ).AnyTimes ().
79
80
DoAndReturn (func (file string ) (fs.File , error ) {
80
81
return wasm .NewVirtualFile (
81
82
file ,
82
- [] byte ( "42" ) ,
83
+ content ,
83
84
time .Unix (1681389446 , 0 )), nil
84
85
})
86
+ mockedFS .EXPECT ().ReadFile (tc .file ).AnyTimes ().
87
+ DoAndReturn (func (file string ) ([]byte , error ) {
88
+ return content , nil
89
+ })
85
90
Convey ("and a filtered file system under test" , func () {
86
91
filteredFS := NewFS (
87
92
mockedFS ,
88
93
lo .Map (tc .whitelist , util .Indexed (util .ParseURLMust )),
89
94
lo .Map (tc .blacklist , util .Indexed (util .ParseURLMust )),
90
95
)
91
96
92
- Convey (fmt .Sprintf (`When the open("%s") is called` , tc .file ), func () {
97
+ Convey (fmt .Sprintf (`when the open("%s") is called` , tc .file ), func () {
93
98
result , err := filteredFS .Open (tc .file )
94
99
95
- Convey ("Then the result should be as expected" , func () {
100
+ Convey ("then the result should be as expected" , func () {
96
101
if util .IsNil (tc .wantError ) {
97
102
So (err , ShouldBeNil )
98
103
@@ -107,9 +112,42 @@ func TestSourceFile(t *testing.T) {
107
112
}
108
113
})
109
114
})
115
+
116
+ Convey (fmt .Sprintf (`when the readFile("%s") is called` , tc .file ), func () {
117
+ result , err := filteredFS .ReadFile (tc .file )
118
+
119
+ Convey ("Then the result should be as expected" , func () {
120
+ if util .IsNil (tc .wantError ) {
121
+ So (err , ShouldBeNil )
122
+ So (result , ShouldResemble , content )
123
+ } else {
124
+ So (err , ShouldNotBeNil )
125
+ So (err , ShouldResemble , tc .wantError )
126
+ }
127
+ })
128
+ })
110
129
})
111
130
})
112
131
})
113
132
}
114
133
})
134
+
135
+ Convey ("Given a mocked fs that does not implement ReadFileFS" , t , func () {
136
+ ctrl := gomock .NewController (t )
137
+ defer ctrl .Finish ()
138
+
139
+ mockedFS := testutil .NewMockFS (ctrl )
140
+ Convey ("and a filtered file system under test" , func () {
141
+ filteredFS := NewFS (mockedFS , nil , nil )
142
+
143
+ Convey ("when readFile is called" , func () {
144
+ _ , err := filteredFS .ReadFile ("file" )
145
+
146
+ Convey ("then an error should be returned" , func () {
147
+ So (err , ShouldNotBeNil )
148
+ So (err , ShouldEqual , & fs.PathError {Op : "readfile" , Path : "file" , Err : fs .ErrInvalid })
149
+ })
150
+ })
151
+ })
152
+ })
115
153
}
0 commit comments