pagemeta_test.go (2280B)
1 // Copyright 2020 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 pagemeta
15
16 import (
17 "fmt"
18 "testing"
19
20 "github.com/gohugoio/hugo/htesting/hqt"
21
22 "github.com/gohugoio/hugo/config"
23
24 qt "github.com/frankban/quicktest"
25 )
26
27 func TestDecodeBuildConfig(t *testing.T) {
28 t.Parallel()
29
30 c := qt.New(t)
31
32 configTempl := `
33 [_build]
34 render = %s
35 list = %s
36 publishResources = true`
37
38 for _, test := range []struct {
39 args []any
40 expect BuildConfig
41 }{
42 {
43 []any{"true", "true"},
44 BuildConfig{
45 Render: Always,
46 List: Always,
47 PublishResources: true,
48 set: true,
49 },
50 },
51 {[]any{"true", "false"}, BuildConfig{
52 Render: Always,
53 List: Never,
54 PublishResources: true,
55 set: true,
56 }},
57 {[]any{`"always"`, `"always"`}, BuildConfig{
58 Render: Always,
59 List: Always,
60 PublishResources: true,
61 set: true,
62 }},
63 {[]any{`"never"`, `"never"`}, BuildConfig{
64 Render: Never,
65 List: Never,
66 PublishResources: true,
67 set: true,
68 }},
69 {[]any{`"link"`, `"local"`}, BuildConfig{
70 Render: Link,
71 List: ListLocally,
72 PublishResources: true,
73 set: true,
74 }},
75 {[]any{`"always"`, `"asdfadf"`}, BuildConfig{
76 Render: Always,
77 List: Always,
78 PublishResources: true,
79 set: true,
80 }},
81 } {
82 cfg, err := config.FromConfigString(fmt.Sprintf(configTempl, test.args...), "toml")
83 c.Assert(err, qt.IsNil)
84 bcfg, err := DecodeBuildConfig(cfg.Get("_build"))
85 c.Assert(err, qt.IsNil)
86
87 eq := qt.CmpEquals(hqt.DeepAllowUnexported(BuildConfig{}))
88
89 c.Assert(bcfg, eq, test.expect)
90
91 }
92 }