github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/resources/resource_factories/create/integration_test.go (about) 1 // Copyright 2023 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package create_test 15 16 import ( 17 "testing" 18 19 "github.com/gohugoio/hugo/hugolib" 20 ) 21 22 func TestGetResourceHead(t *testing.T) { 23 24 files := ` 25 -- config.toml -- 26 [security] 27 [security.http] 28 methods = ['(?i)GET|POST|HEAD'] 29 urls = ['.*gohugo\.io.*'] 30 31 -- layouts/index.html -- 32 {{ $url := "https://gohugo.io/img/hugo.png" }} 33 {{ $opts := dict "method" "head" }} 34 {{ with resources.GetRemote $url $opts }} 35 {{ with .Err }} 36 {{ errorf "Unable to get remote resource: %s" . }} 37 {{ else }} 38 Head Content: {{ .Content }}. Head Data: {{ .Data }} 39 {{ end }} 40 {{ else }} 41 {{ errorf "Unable to get remote resource: %s" $url }} 42 {{ end }} 43 ` 44 45 b := hugolib.NewIntegrationTestBuilder( 46 hugolib.IntegrationTestConfig{ 47 T: t, 48 TxtarString: files, 49 }, 50 ) 51 52 b.Build() 53 54 b.AssertFileContent("public/index.html", 55 "Head Content: .", 56 "Head Data: map[ContentLength:18210 ContentType:image/png Status:200 OK StatusCode:200 TransferEncoding:[]]", 57 ) 58 59 }