-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanifest_test.go
66 lines (54 loc) · 1.61 KB
/
manifest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package staticfiles
import (
"github.com/stretchr/testify/suite"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
type ManifestTestSuite struct {
suite.Suite
StoragePath string
ManifestPath string
}
func TestManifestTestSuite(t *testing.T) {
suite.Run(t, &ManifestTestSuite{
StoragePath: os.TempDir(),
})
}
func (s *ManifestTestSuite) SetupTest() {
s.ManifestPath = filepath.Join(s.StoragePath, ManifestFilename)
if _, err := os.Stat(s.ManifestPath); err == nil {
os.Remove(s.ManifestPath)
}
}
func (s *ManifestTestSuite) TearDownTest() {
os.Remove(s.ManifestPath)
}
func (s *ManifestTestSuite) TestManifestNotExist() {
_, err := loadManifest(s.StoragePath)
s.Assert().True(os.IsNotExist(err))
}
func (s *ManifestTestSuite) TestManifestVersionMismatch() {
err := ioutil.WriteFile(s.ManifestPath, []byte(`{"paths":{},"version":0}`), 0644)
s.Require().NoError(err)
_, err = loadManifest(s.StoragePath)
s.Assert().Equal(ErrManifestVersionMismatch, err)
}
func (s *ManifestTestSuite) TestLoadManifest() {
err := ioutil.WriteFile(s.ManifestPath, []byte(`{"paths":{"style.css":"style.5f15d96d5cdb4d0d5eb6901181826a04.css","pix.png":"pix.3eaf17869bb51bf27bd7c91bc9853973.png"},"version":1}`), 0644)
s.Require().NoError(err)
filesMap, err := loadManifest(s.StoragePath)
s.Require().NoError(err)
manifestFilesMap := map[string]*StaticFile{
"style.css": {
RelPath: "style.css",
StorageRelPath: "style.5f15d96d5cdb4d0d5eb6901181826a04.css",
},
"pix.png": {
RelPath: "pix.png",
StorageRelPath: "pix.3eaf17869bb51bf27bd7c91bc9853973.png",
},
}
s.Assert().Equal(manifestFilesMap, filesMap)
}