Debian Codegraph @

config/services/servicesConfig_test.go

raw
1 // Copyright 2018 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 services
15
16 import (
17 "testing"
18
19 qt "github.com/frankban/quicktest"
20 "github.com/gohugoio/hugo/config"
21 )
22
23 func TestDecodeConfigFromTOML(t *testing.T) {
24 c := qt.New(t)
25
26 tomlConfig := `
27
28 someOtherValue = "foo"
29
30 [services]
31 [services.disqus]
32 shortname = "DS"
33 [services.googleAnalytics]
34 id = "ga_id"
35 [services.instagram]
36 disableInlineCSS = true
37 [services.twitter]
38 disableInlineCSS = true
39 [services.x]
40 disableInlineCSS = true
41 `
42 cfg, err := config.FromConfigString(tomlConfig, "toml")
43 c.Assert(err, qt.IsNil)
44
45 config, err := DecodeConfig(cfg)
46 c.Assert(err, qt.IsNil)
47 c.Assert(config, qt.Not(qt.IsNil))
48
49 c.Assert(config.Disqus.Shortname, qt.Equals, "DS")
50 c.Assert(config.GoogleAnalytics.ID, qt.Equals, "ga_id")
51
52 c.Assert(config.Instagram.DisableInlineCSS, qt.Equals, true)
53 }
54
55 // Support old root-level GA settings etc.
56 func TestUseSettingsFromRootIfSet(t *testing.T) {
57 c := qt.New(t)
58
59 cfg := config.New()
60 cfg.Set("disqusShortname", "root_short")
61 cfg.Set("googleAnalytics", "ga_root")
62
63 config, err := DecodeConfig(cfg)
64 c.Assert(err, qt.IsNil)
65 c.Assert(config, qt.Not(qt.IsNil))
66
67 c.Assert(config.Disqus.Shortname, qt.Equals, "root_short")
68 c.Assert(config.GoogleAnalytics.ID, qt.Equals, "ga_root")
69 }