diff options
author | Noah Campbell <noahcampbell@gmail.com> | 2013-09-20 17:03:43 -0700 |
---|---|---|
committer | Noah Campbell <noahcampbell@gmail.com> | 2013-09-20 17:03:43 -0700 |
commit | 52e8c7a0ac76f4aa1fff8ff30a6d5074bd459347 (patch) | |
tree | fcabd15f6b496589edcf56be200f865177606a70 /source/filesystem_test.go | |
parent | 784077da4dcc3476f61bbf99c5f873b71694dd64 (diff) | |
download | hugo-52e8c7a0ac76f4aa1fff8ff30a6d5074bd459347.tar.gz hugo-52e8c7a0ac76f4aa1fff8ff30a6d5074bd459347.zip |
Section is determined by the source, not the url
This change allows for top level html content to exists.
Diffstat (limited to 'source/filesystem_test.go')
-rw-r--r-- | source/filesystem_test.go | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/source/filesystem_test.go b/source/filesystem_test.go index 2aac9b0dc..b885d2f24 100644 --- a/source/filesystem_test.go +++ b/source/filesystem_test.go @@ -2,6 +2,8 @@ package source import ( "bytes" + "path" + "path/filepath" "testing" ) @@ -12,21 +14,58 @@ func TestEmptySourceFilesystem(t *testing.T) { } } +type TestPath struct { + filename string + logical string + content string + section string + dir string +} + func TestAddFile(t *testing.T) { - src := new(Filesystem) - src.add("foobar", bytes.NewReader([]byte("aaa"))) - if len(src.Files()) != 1 { - t.Errorf("Files() should return 1 file") - } + tests := platformPaths + for _, test := range tests { + base := platformBase + srcDefault := new(Filesystem) + srcWithBase := &Filesystem{ + Base: base, + } - f := src.Files()[0] - if f.Name != "foobar" { - t.Errorf("File name should be 'foobar', got: %s", f.Name) - } + for _, src := range []*Filesystem{srcDefault, srcWithBase} { + p := test.filename + if !filepath.IsAbs(test.filename) { + p = path.Join(src.Base, test.filename) + } + + if err := src.add(p, bytes.NewReader([]byte(test.content))); err != nil { + if err == errMissingBaseDir { + continue + } + t.Fatalf("%s add returned and error: %s", p, err) + } + + if len(src.Files()) != 1 { + t.Fatalf("%s Files() should return 1 file", p) + } + + f := src.Files()[0] + if f.LogicalName != test.logical { + t.Errorf("Filename (Base: %q) expected: %q, got: %q", src.Base, test.logical, f.LogicalName) + } + + b := new(bytes.Buffer) + b.ReadFrom(f.Contents) + if b.String() != test.content { + t.Errorf("File (Base: %q) contents should be %q, got: %q", src.Base, test.content, b.String()) + } + + if f.Section != test.section { + t.Errorf("File section (Base: %q) expected: %q, got: %q", src.Base, test.section, f.Section) + } - b := new(bytes.Buffer) - b.ReadFrom(f.Contents) - if b.String() != "aaa" { - t.Errorf("File contents should be 'aaa', got: %s", b.String()) + if f.Dir != test.dir { + t.Errorf("Dir path (Base: %q) expected: %q, got: %q", src.Base, test.dir, f.Dir) + } + } } } |