mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-19 20:23:00 +00:00
openapi3: Port integration test into correct package
This commit is contained in:
parent
64f75adcf6
commit
39f69ca7f0
1 changed files with 26 additions and 18 deletions
|
@ -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");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with 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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package hugolib
|
package openapi3_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gohugoio/hugo/hugolib"
|
||||||
|
|
||||||
|
qt "github.com/frankban/quicktest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOpenAPI3(t *testing.T) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
const openapi3Yaml = `openapi: 3.0.0
|
c := qt.New(t)
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- assets/api/myapi.yaml --
|
||||||
|
openapi: 3.0.0
|
||||||
info:
|
info:
|
||||||
title: Sample API
|
title: Sample API
|
||||||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
||||||
|
@ -43,26 +51,26 @@ paths:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
type: string
|
type: string
|
||||||
`
|
-- config.toml --
|
||||||
|
baseURL = 'http://example.com/'
|
||||||
b := newTestSitesBuilder(t).Running()
|
-- layouts/index.html --
|
||||||
b.WithSourceFile("assets/api/myapi.yaml", openapi3Yaml)
|
|
||||||
|
|
||||||
b.WithTemplatesAdded("index.html", `
|
|
||||||
{{ $api := resources.Get "api/myapi.yaml" | openapi3.Unmarshal }}
|
{{ $api := resources.Get "api/myapi.yaml" | openapi3.Unmarshal }}
|
||||||
|
|
||||||
API: {{ $api.Info.Title | safeHTML }}
|
API: {{ $api.Info.Title | safeHTML }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.NewIntegrationTestBuilder(
|
||||||
`)
|
hugolib.IntegrationTestConfig{
|
||||||
|
T: c,
|
||||||
b.Build(BuildCfg{})
|
Running: true,
|
||||||
|
TxtarString: files,
|
||||||
|
},
|
||||||
|
).Build()
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", `API: Sample API`)
|
b.AssertFileContent("public/index.html", `API: Sample API`)
|
||||||
|
|
||||||
b.EditFiles("assets/api/myapi.yaml", strings.Replace(openapi3Yaml, "Sample API", "Hugo API", -1))
|
b.
|
||||||
|
EditFileReplace("assets/api/myapi.yaml", func(s string) string { return strings.ReplaceAll(s, "Sample API", "Hugo API") }).
|
||||||
b.Build(BuildCfg{})
|
Build()
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", `API: Hugo API`)
|
b.AssertFileContent("public/index.html", `API: Hugo API`)
|
||||||
}
|
}
|
Loading…
Reference in a new issue