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