-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeta_test.go
80 lines (64 loc) · 2.17 KB
/
meta_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
75
76
77
78
79
80
package main
import (
"io/ioutil"
"os"
"strings"
"testing"
"github.com/davecgh/go-spew/spew"
)
func TestLoadMeta(t *testing.T) {
// TODO improve all this to use table tests
fn := ".testfile.md"
ioutil.WriteFile(fn, []byte(`
{
// You can use c-style comments as long as they are on their own
// line and use the // format (not /* */)
// Title is ALWAYS required. You can control how this is used in
// base.html
"title": "Great Blog Post Aboot Cats!",
// Used in OG tags and can be used in recent posts promo
"desc": "Here is a short(ish) description about this article",
// Headlines can be used in various ways. More on this later
"hl1": "Headlines could be variations on title for",
"hl2": "a/b testing purposes or",
"hl3": "auto tweeting so you post your content multiple times spread out",
// Specify a relative or full URL to the article's canonical image.
// We'll set article's og:image tag to this
"image": "/static/img/hello.jpg",
"image_alt": "A hello face",
// If set to true, this page will go live with grumpo gen
// However it wont show up in recent posts until you set
// a publish date
"live": false,
// Both support the format 2020-01-01 OR 2020-01-01:03:04:05
// No other formats are supported and no timezones can be passed in
// grumpo commands use your machine's local time zone
"publish_date": "2050-01-01",
"updated_date": "2100-01-01",
// Defaults to false. Set to true to treat this page as a full html page
"skip_base_template": true
}
# Some Random Page W/ Markdowns!
Hellos thers somethingslkjsdl falksjf aslkfjas
More shit that would normally be in a real content/MD file
`), 0777)
m, err := loadMeta(fn)
if err != nil {
t.Error(err)
} else {
t.Logf("Meta: (%s)", spew.Sdump(m))
if m.contentStartsOn != 37 {
t.Errorf("Expected content starts on 37, got %d", m.contentStartsOn)
}
fileBytes, err := readOffsetFile(fn, 37)
if err != nil {
t.Error(err)
} else if !strings.HasPrefix(strings.TrimSpace(string(fileBytes)), "# Some Random Page") {
t.Error("didnt find the rest of the file on offset!!")
}
}
err = os.Remove(fn)
if err != nil {
t.Error(err)
}
}