From 39f69ca7f078fe00ca80eef8f512f894a78e8f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 9 Feb 2022 13:45:38 +0100 Subject: [PATCH] openapi3: Port integration test into correct package --- .../openapi/openapi3/integration_test.go | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) rename hugolib/openapi_test.go => tpl/openapi/openapi3/integration_test.go (71%) diff --git a/hugolib/openapi_test.go b/tpl/openapi/openapi3/integration_test.go similarity index 71% rename from hugolib/openapi_test.go rename to tpl/openapi/openapi3/integration_test.go index 3f1bc400dc0..2b0730154c3 100644 --- a/hugolib/openapi_test.go +++ b/tpl/openapi/openapi3/integration_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Hugo Authors. All rights reserved. +// Copyright 2021 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,15 +11,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -package hugolib +package openapi3_test import ( "strings" "testing" + + "github.com/gohugoio/hugo/hugolib" + + qt "github.com/frankban/quicktest" ) -func TestOpenAPI3(t *testing.T) { - const openapi3Yaml = `openapi: 3.0.0 +func TestUnmarshal(t *testing.T) { + c := qt.New(t) + + files := ` +-- assets/api/myapi.yaml -- +openapi: 3.0.0 info: title: Sample API description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. @@ -43,26 +51,26 @@ paths: type: array items: type: string -` - - b := newTestSitesBuilder(t).Running() - b.WithSourceFile("assets/api/myapi.yaml", openapi3Yaml) - - b.WithTemplatesAdded("index.html", ` +-- config.toml -- +baseURL = 'http://example.com/' +-- layouts/index.html -- {{ $api := resources.Get "api/myapi.yaml" | openapi3.Unmarshal }} - API: {{ $api.Info.Title | safeHTML }} + ` - -`) - - b.Build(BuildCfg{}) + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: c, + Running: true, + TxtarString: files, + }, + ).Build() b.AssertFileContent("public/index.html", `API: Sample API`) - b.EditFiles("assets/api/myapi.yaml", strings.Replace(openapi3Yaml, "Sample API", "Hugo API", -1)) - - b.Build(BuildCfg{}) + b. + EditFileReplace("assets/api/myapi.yaml", func(s string) string { return strings.ReplaceAll(s, "Sample API", "Hugo API") }). + Build() b.AssertFileContent("public/index.html", `API: Hugo API`) }