@@ -173,8 +173,24 @@ func TestWriteFile(t *testing.T) {
173173 }
174174 })
175175
176- t .Run ("binary" , func (t * testing.T ) {
177- path := filepath .Join (dir , "data.bin" )
176+ t .Run ("data-octet-stream" , func (t * testing.T ) {
177+ path := filepath .Join (dir , "data-1.bin" )
178+ err = WriteFile (path , "data:application/octet-stream;base64,MTIz" , 0444 )
179+ if err != nil {
180+ t .Fatalf ("expected nil err, got %v" , err )
181+ }
182+ got , err := os .ReadFile (path )
183+ if err != nil {
184+ t .Fatalf ("read file: expected nil err, got %v" , err )
185+ }
186+ want := []byte ("123" )
187+ if ! reflect .DeepEqual (got , want ) {
188+ t .Errorf ("read file: expected %v, got %v" , want , got )
189+ }
190+ })
191+
192+ t .Run ("data-base64" , func (t * testing.T ) {
193+ path := filepath .Join (dir , "data-2.bin" )
178194 err = WriteFile (path , "data:;base64,MTIz" , 0444 )
179195 if err != nil {
180196 t .Fatalf ("expected nil err, got %v" , err )
@@ -189,6 +205,22 @@ func TestWriteFile(t *testing.T) {
189205 }
190206 })
191207
208+ t .Run ("data-text-plain" , func (t * testing.T ) {
209+ path := filepath .Join (dir , "data-3.bin" )
210+ err = WriteFile (path , "data:text/plain;,123" , 0444 )
211+ if err != nil {
212+ t .Fatalf ("expected nil err, got %v" , err )
213+ }
214+ got , err := os .ReadFile (path )
215+ if err != nil {
216+ t .Fatalf ("read file: expected nil err, got %v" , err )
217+ }
218+ want := []byte ("123" )
219+ if ! reflect .DeepEqual (got , want ) {
220+ t .Errorf ("read file: expected %v, got %v" , want , got )
221+ }
222+ })
223+
192224 t .Run ("perm" , func (t * testing.T ) {
193225 const perm = 0444
194226 path := filepath .Join (dir , "perm.txt" )
0 commit comments