mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
db945a6ed2
commit
a99fed4852
2 changed files with 33 additions and 3 deletions
|
@ -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
|
||||
|
||||
`)
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue