diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-11-17 17:17:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-11-17 18:09:54 +0100 |
commit | a99fed4852b65f94f4936fbc6c308068c05f2a2d (patch) | |
tree | 1ba8bb0b28aa523179f51ab2cc7f78982fd21b56 /tpl | |
parent | db945a6ed2ab12de04502957151d55779cbdd39d (diff) |
resources/tpl: Add a test for resources.Get
Updates #10101
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/resources/integration_test.go | 29 | ||||
-rw-r--r-- | tpl/resources/resources.go | 7 |
2 files changed, 33 insertions, 3 deletions
diff --git a/tpl/resources/integration_test.go b/tpl/resources/integration_test.go index 7662f7b6b..0e0a29a98 100644 --- a/tpl/resources/integration_test.go +++ b/tpl/resources/integration_test.go @@ -98,3 +98,32 @@ func TestCopyPageShouldFail(t *testing.T) { b.Assert(err, qt.IsNotNil) } + +func TestGet(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +baseURL = "http://example.com/blog" +-- assets/images/pixel.png -- +iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg== +-- layouts/index.html -- +{{ with resources.Get "images/pixel.png" }}Image OK{{ else }}Image not found{{ end }} +{{ with resources.Get "" }}Failed{{ else }}Empty string not found{{ end }} + + + ` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + TxtarString: files, + }).Build() + + b.AssertFileContent("public/index.html", ` +Image OK +Empty string not found + + `) + +} diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go index d8f06761d..fe6fd0434 100644 --- a/tpl/resources/resources.go +++ b/tpl/resources/resources.go @@ -125,13 +125,14 @@ func (ns *Namespace) Copy(s any, r resource.Resource) (resource.Resource, error) func (ns *Namespace) Get(filename any) resource.Resource { filenamestr, err := cast.ToStringE(filename) + if err != nil { + panic(err) + } if filenamestr == "" { return nil } - if err != nil { - panic(err) - } + r, err := ns.createClient.Get(filenamestr) if err != nil { panic(err) |