diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-05 11:07:50 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-06 10:29:13 +0100 |
commit | f25d8a9e17fb65fa41dafdcbf0358853d68eaf45 (patch) | |
tree | fd8932fdf88b3774b5773866c5f8ceadea2cc15a /resource/resource_test.go | |
parent | 54a89cde69c1fcda7afe0ba0f4e0de86f5f69aa5 (diff) |
Fix sub-folder baseURL handling for Page resources
I.e. images etc.
Fixes #4228
Diffstat (limited to 'resource/resource_test.go')
-rw-r--r-- | resource/resource_test.go | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/resource/resource_test.go b/resource/resource_test.go index 34d63cd60..847c26843 100644 --- a/resource/resource_test.go +++ b/resource/resource_test.go @@ -28,7 +28,7 @@ func TestGenericResource(t *testing.T) { r := spec.newGenericResource(nil, nil, "/public", "/a/foo.css", "foo.css", "css") assert.Equal("https://example.com/foo.css", r.Permalink()) - assert.Equal("foo.css", r.RelPermalink()) + assert.Equal("/foo.css", r.RelPermalink()) assert.Equal("css", r.ResourceType()) } @@ -60,7 +60,7 @@ func TestNewResourceFromFilename(t *testing.T) { assert.NoError(err) assert.NotNil(r) assert.Equal("image", r.ResourceType()) - assert.Equal("a/b/logo.png", r.RelPermalink()) + assert.Equal("/a/b/logo.png", r.RelPermalink()) assert.Equal("https://example.com/a/b/logo.png", r.Permalink()) r, err = spec.NewResourceFromFilename(nil, "/public", "/root/a/b/data.json", "a/b/data.json") @@ -74,6 +74,25 @@ func TestNewResourceFromFilename(t *testing.T) { assert.Equal("/aceof/a/b/data.json", cloned.RelPermalink()) } +func TestNewResourceFromFilenameSubPathInBaseURL(t *testing.T) { + assert := require.New(t) + spec := newTestResourceSpecForBaseURL(assert, "https://example.com/docs") + + writeSource(t, spec.Fs, "/project/a/b/logo.png", "image") + + r, err := spec.NewResourceFromFilename(nil, "/public", + filepath.FromSlash("/project/a/b/logo.png"), filepath.FromSlash("a/b/logo.png")) + + assert.NoError(err) + assert.NotNil(r) + assert.Equal("image", r.ResourceType()) + assert.Equal("/docs/a/b/logo.png", r.RelPermalink()) + assert.Equal("https://example.com/docs/a/b/logo.png", r.Permalink()) + img := r.(*Image) + assert.Equal("/a/b/logo.png", img.target()) + +} + func TestResourcesByType(t *testing.T) { assert := require.New(t) spec := newTestResourceSpec(assert) @@ -99,10 +118,10 @@ func TestResourcesGetByPrefix(t *testing.T) { spec.newGenericResource(nil, nil, "/public", "/b/foo3.css", "foo3.css", "css")} assert.Nil(resources.GetByPrefix("asdf")) - assert.Equal("logo1.png", resources.GetByPrefix("logo").RelPermalink()) - assert.Equal("foo2.css", resources.GetByPrefix("foo2").RelPermalink()) - assert.Equal("foo1.css", resources.GetByPrefix("foo1").RelPermalink()) - assert.Equal("foo1.css", resources.GetByPrefix("foo1").RelPermalink()) + assert.Equal("/logo1.png", resources.GetByPrefix("logo").RelPermalink()) + assert.Equal("/foo2.css", resources.GetByPrefix("foo2").RelPermalink()) + assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink()) + assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink()) assert.Nil(resources.GetByPrefix("asdfasdf")) } |