...
1
16
17 package testfiles
18
19 import (
20 "embed"
21 "testing"
22
23 "github.com/stretchr/testify/assert"
24 )
25
26 var (
27 fooContents = `Hello World
28 `
29 fooPath = "testdata/a/foo.txt"
30
31 notExistsPath = "testdata/b"
32
33 expectedDescription = `The following files are embedded into the test executable:
34 testdata/a/foo.txt`
35 )
36
37
38 var testFS embed.FS
39
40 func getTestEmbeddedSource() *EmbeddedFileSource {
41 return &EmbeddedFileSource{
42 EmbeddedFS: testFS,
43 }
44 }
45
46 func TestEmbeddedFileSource(t *testing.T) {
47 s := getTestEmbeddedSource()
48
49
50 b, err := s.ReadTestFile(fooPath)
51
52 assert.NoError(t, err)
53 assert.Equal(t, fooContents, string(b))
54
55
56
57 b, err = s.ReadTestFile(notExistsPath)
58 assert.NoError(t, err)
59 assert.Empty(t, b)
60
61
62 assert.Equal(t, expectedDescription, s.DescribeFiles())
63 }
64
View as plain text