Move timezone tests to integration test.

Interacting with timezones will result in checks against the filesystem.
This access, by definition, is an integration test.  Creating a
*integration_test.go file will signify this change.

When interacting with Travis-ci.org, the ubuntu boxes plus go 1.1 do not
seem to support shortcode timezones, think PST.  In this case, the tests
are skipped.  This is not ideal, but the IRC #go-nuts channel has
indicated timezone support is still lacking.  We should advise users of
hugo that timezone support may be an issue and report any odd behavior.
The workaround is to use numeric timezones (-08:00 for PST, etc.)
This commit is contained in:
Noah Campbell 2013-08-12 09:41:41 -07:00
parent f610d45cd8
commit 0305c82513
3 changed files with 106 additions and 86 deletions

View file

@ -1,3 +1,3 @@
language: go language: go
go: go:
- 1.1 - 1.1

View file

@ -5,7 +5,6 @@ import (
"io" "io"
"strings" "strings"
"testing" "testing"
"time"
) )
var EMPTY_PAGE = "" var EMPTY_PAGE = ""
@ -70,51 +69,6 @@ var SIMPLE_PAGE_JSON_COMPACT = `
Text Text
` `
var PAGE_WITH_INVALID_DATE = `---
date: 2010-05-02 15:29:31+08:00
---
Page With Invalid Date (missing the T for RFC 3339)`
var PAGE_WITH_DATE_RFC3339 = `---
date: 2010-05-02T15:29:31+08:00
---
Page With Date RFC3339`
var PAGE_WITH_DATE_RFC1123 = `---
date: Sun, 02 May 2010 15:29:31 PST
---
Page With Date RFC1123`
var PAGE_WITH_DATE_RFC1123Z = `---
date: Sun, 02 May 2010 15:29:31 +0800
---
Page With Date RFC1123Z`
var PAGE_WITH_DATE_RFC822 = `---
date: 02 May 10 15:29 PST
---
Page With Date RFC822`
var PAGE_WITH_DATE_RFC822Z = `---
date: 02 May 10 15:29 +0800
---
Page With Date RFC822Z`
var PAGE_WITH_DATE_ANSIC = `---
date: Sun May 2 15:29:31 2010
---
Page With Date ANSIC`
var PAGE_WITH_DATE_UnixDate = `---
date: Sun May 2 15:29:31 PST 2010
---
Page With Date UnixDate`
var PAGE_WITH_DATE_RubyDate = `---
date: Sun May 02 15:29:31 +0800 2010
---
Page With Date RubyDate`
func checkError(t *testing.T, err error, expected string) { func checkError(t *testing.T, err error, expected string) {
if err == nil { if err == nil {
t.Fatalf("err is nil") t.Fatalf("err is nil")
@ -215,40 +169,3 @@ func TestDegenerateInvalidFrontMatterLeadingWhitespace(t *testing.T) {
t.Fatalf("Unable to parse front matter given leading whitespace: %s", err) t.Fatalf("Unable to parse front matter given leading whitespace: %s", err)
} }
} }
func TestDegenerateDateFrontMatter(t *testing.T) {
p, _ := ReadFrom(strings.NewReader(PAGE_WITH_INVALID_DATE), "page/with/invalid/date")
if p.Date != time.Unix(0, 0) {
t.Fatalf("Date should be set to computer epoch. Got: %s", p.Date)
}
}
func TestParsingDateInFrontMatter(t *testing.T) {
for _, test := range []struct {
buf string
dt string
}{
{PAGE_WITH_DATE_RFC3339, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC1123, "2010-05-02T15:29:31-08:00"},
{PAGE_WITH_DATE_RFC1123Z, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC822, "2010-05-02T15:29:00-08:00"},
{PAGE_WITH_DATE_RFC822Z, "2010-05-02T15:29:00+08:00"},
{PAGE_WITH_DATE_ANSIC, "2010-05-02T15:29:31Z"},
{PAGE_WITH_DATE_UnixDate, "2010-05-02T15:29:31-08:00"},
{PAGE_WITH_DATE_RubyDate, "2010-05-02T15:29:31+08:00"},
} {
dt, e := time.Parse(time.RFC3339, test.dt)
if e != nil {
t.Fatalf("Unable to parse date time (RFC3339) for running the test: %s", e)
}
p, err := ReadFrom(strings.NewReader(test.buf), "page/with/date")
if err != nil {
t.Fatalf("Expected to be able to parse page.")
}
if !dt.Equal(p.Date) {
//if dt != p.Date {
t.Errorf("Date does not equal frontmatter:\n%s\nExpecting: %s\n Got: %s. Diff: %s\n internal: %#v\n %#v", test.buf, dt, p.Date, dt.Sub(p.Date), dt, p.Date)
}
}
}

View file

@ -0,0 +1,103 @@
package hugolib
import (
"fmt"
"os"
"strings"
"testing"
"time"
)
var PAGE_WITH_INVALID_DATE = `---
date: 2010-05-02 15:29:31+08:00
---
Page With Invalid Date (missing the T for RFC 3339)`
var PAGE_WITH_DATE_RFC3339 = `---
date: 2010-05-02T15:29:31+08:00
---
Page With Date RFC3339`
var PAGE_WITH_DATE_RFC1123 = `---
date: Sun, 02 May 2010 15:29:31 PST
---
Page With Date RFC1123`
var PAGE_WITH_DATE_RFC1123Z = `---
date: Sun, 02 May 2010 15:29:31 +0800
---
Page With Date RFC1123Z`
var PAGE_WITH_DATE_RFC822 = `---
date: 02 May 10 15:29 PST
---
Page With Date RFC822`
var PAGE_WITH_DATE_RFC822Z = `---
date: 02 May 10 15:29 +0800
---
Page With Date RFC822Z`
var PAGE_WITH_DATE_ANSIC = `---
date: Sun May 2 15:29:31 2010
---
Page With Date ANSIC`
var PAGE_WITH_DATE_UnixDate = `---
date: Sun May 2 15:29:31 PST 2010
---
Page With Date UnixDate`
var PAGE_WITH_DATE_RubyDate = `---
date: Sun May 02 15:29:31 +0800 2010
---
Page With Date RubyDate`
func TestDegenerateDateFrontMatter(t *testing.T) {
p, _ := ReadFrom(strings.NewReader(PAGE_WITH_INVALID_DATE), "page/with/invalid/date")
if p.Date != time.Unix(0, 0) {
t.Fatalf("Date should be set to computer epoch. Got: %s", p.Date)
}
}
func TestParsingDateInFrontMatter(t *testing.T) {
tests := []struct {
buf string
dt string
}{
{PAGE_WITH_DATE_RFC3339, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC1123Z, "2010-05-02T15:29:31+08:00"},
{PAGE_WITH_DATE_RFC822Z, "2010-05-02T15:29:00+08:00"},
{PAGE_WITH_DATE_ANSIC, "2010-05-02T15:29:31Z"},
{PAGE_WITH_DATE_RubyDate, "2010-05-02T15:29:31+08:00"},
}
tzShortCodeTests := []struct {
buf string
dt string
}{
{PAGE_WITH_DATE_RFC1123, "2010-05-02T15:29:31-08:00"},
{PAGE_WITH_DATE_RFC822, "2010-05-02T15:29:00-08:00"},
{PAGE_WITH_DATE_UnixDate, "2010-05-02T15:29:31-08:00"},
}
if _, err := time.LoadLocation("PST"); err == nil {
tests = append(tests, tzShortCodeTests...)
} else {
fmt.Fprintf(os.Stderr, "Skipping shortname timezone tests.\n")
}
for _, test := range tests {
dt, e := time.Parse(time.RFC3339, test.dt)
if e != nil {
t.Fatalf("Unable to parse date time (RFC3339) for running the test: %s", e)
}
p, err := ReadFrom(strings.NewReader(test.buf), "page/with/date")
if err != nil {
t.Fatalf("Expected to be able to parse page.")
}
if !dt.Equal(p.Date) {
t.Errorf("Date does not equal frontmatter:\n%s\nExpecting: %s\n Got: %s. Diff: %s\n internal: %#v\n %#v", test.buf, dt, p.Date, dt.Sub(p.Date), dt, p.Date)
}
}
}