-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain_test.go
69 lines (61 loc) Β· 1.7 KB
/
main_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
67
68
69
package main
import (
"fmt"
"os"
"testing"
"github.com/spf13/afero"
)
func TestGetFileURL(t *testing.T) {
tests := []struct {
bucket string
bucketFilename string
expected string
}{
{"some-bucket", "js/app.1234.js", "https://s3.amazonaws.com/some-bucket/js/app.1234.js"},
{"static.buffer.com", "dir/js/app.1234.js", "https://static.buffer.com/dir/js/app.1234.js"},
}
for _, test := range tests {
actual := GetFileURL(test.bucket, test.bucketFilename)
if actual != test.expected {
t.Errorf("File URL was incorrect, got: %s, expected %s", actual, test.expected)
}
}
}
func TestShouldVersionFile(t *testing.T) {
tests := []struct {
filename string
expected bool
}{
{"bundle.js", true},
{"assets.css", true},
{"another.file", false},
}
for _, test := range tests {
actual := ShouldVersionFile(test.filename)
if actual != test.expected {
t.Errorf("ShouldVersionFile result was incorrect, got %t, expected %t for filename %s", actual, test.expected, test.filename)
}
}
}
func TestGetUploadFilename(t *testing.T) {
var AppFs = afero.NewMemMapFs()
filename := "bundle.js"
file, _ := AppFs.OpenFile(filename, os.O_CREATE, 0600)
file.WriteString("some JS content")
tests := []struct {
file afero.File
filename string
skipVersioning bool
expected string
}{
{file, filename, false, "bundle.d41d8cd98f00b204e9800998ecf8427e.js"},
{file, filename, true, "bundle.js"},
}
for _, test := range tests {
fmt.Print(file.Name())
actual, _ := GetUploadFilename(test.file, test.filename, test.skipVersioning)
if actual != test.expected {
t.Errorf("GetUploadFilename result was incorrect, got %s, expected %s", actual, test.expected)
}
}
}