-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconverter_test.go
74 lines (59 loc) · 1.45 KB
/
converter_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
70
71
72
73
74
package main
import (
"context"
"testing"
)
func TestConverter_LocalToGCS(t *testing.T) {
c := newConverter(t)
ctx := context.Background()
fn := "README.md"
lfp := "/Users/sinmetal/go/src/github.com/gcpug/nouhau2web/README.md"
if err := c.Process(ctx, lfp, "gcpug-nouhau-test", fn); err != nil {
t.Fatal(err)
}
}
func TestConverter_ContentType(t *testing.T) {
c := newConverter(t)
ext, _ := c.ContentType("hoge.MD")
if e, g := ".md", ext; e != g {
t.Errorf("Ext want %v got %v", e, g)
}
}
func TestConverter_ObjectPath(t *testing.T) {
cases := []struct {
name string
root string
lfp string
want string
}{
{"fullPath", "/Users/sinmetal/hoge", "/Users/sinmetal/hoge/fuga.MD", "fuga.html"},
{"currentPathMarkdown", ".", "./hoge/fuga.MD", "hoge/fuga.html"},
{"currentPathText", ".", "./hoge/fuga.txt", "hoge/fuga.txt"},
}
for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
c := newConverterWithRoot(t, tt.root)
got := c.ObjectPath(tt.lfp)
if got != tt.want {
t.Errorf("want %s but got %s", tt.want, got)
}
})
}
}
func newConverter(t *testing.T) *Converter {
ctx := context.Background()
gcs, err := NewStorageService(ctx)
if err != nil {
t.Fatal(err)
}
return NewConverter(gcs, ".")
}
func newConverterWithRoot(t *testing.T, root string) *Converter {
ctx := context.Background()
gcs, err := NewStorageService(ctx)
if err != nil {
t.Fatal(err)
}
return NewConverter(gcs, root)
}