Debian Codegraph @

config/namespace_test.go

raw
1 // Copyright 2024 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 config
15
16 import (
17 "strings"
18 "testing"
19
20 qt "github.com/frankban/quicktest"
21 "github.com/gohugoio/hugo/common/hmaps"
22 "github.com/mitchellh/mapstructure"
23 )
24
25 func TestNamespace(t *testing.T) {
26 c := qt.New(t)
27 c.Assert(true, qt.Equals, true)
28
29 // ns, err := config.DecodeNamespace[map[string]DocsMediaTypeConfig](in, defaultMediaTypesConfig, buildConfig)
30
31 ns, err := DecodeNamespace[[]*tstNsExt](
32 map[string]any{"foo": "bar"},
33 func(v any) (*tstNsExt, any, error) {
34 t := &tstNsExt{}
35 m, err := hmaps.ToStringMapE(v)
36 if err != nil {
37 return nil, nil, err
38 }
39 return t, nil, mapstructure.WeakDecode(m, t)
40 },
41 )
42
43 c.Assert(err, qt.IsNil)
44 c.Assert(ns, qt.Not(qt.IsNil))
45 c.Assert(ns.SourceStructure, qt.DeepEquals, map[string]any{"foo": "bar"})
46 c.Assert(ns.SourceHash, qt.Equals, "1420f6c7782f7459")
47 c.Assert(ns.Config, qt.DeepEquals, &tstNsExt{Foo: "bar"})
48 c.Assert(ns.Signature(), qt.DeepEquals, []*tstNsExt(nil))
49 }
50
51 type (
52 tstNsExt struct {
53 Foo string
54 }
55 )
56
57 func (t *tstNsExt) Init() error {
58 t.Foo = strings.ToUpper(t.Foo)
59 return nil
60 }