github.com/shohhei1126/hugo@v0.42.2-0.20180623210752-3d5928889ad7/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 "github.com/gohugoio/hugo/config" 20 "github.com/spf13/viper" 21 "github.com/stretchr/testify/require" 22 ) 23 24 func TestDecodeConfigFromTOML(t *testing.T) { 25 assert := require.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 assert.NoError(err) 43 44 config, err := DecodeConfig(cfg) 45 assert.NoError(err) 46 assert.NotNil(config) 47 48 assert.Equal("DS", config.Disqus.Shortname) 49 assert.Equal("ga_id", config.GoogleAnalytics.ID) 50 51 assert.True(config.Instagram.DisableInlineCSS) 52 } 53 54 // Support old root-level GA settings etc. 55 func TestUseSettingsFromRootIfSet(t *testing.T) { 56 assert := require.New(t) 57 58 cfg := viper.New() 59 cfg.Set("disqusShortname", "root_short") 60 cfg.Set("googleAnalytics", "ga_root") 61 62 config, err := DecodeConfig(cfg) 63 assert.NoError(err) 64 assert.NotNil(config) 65 66 assert.Equal("root_short", config.Disqus.Shortname) 67 assert.Equal("ga_root", config.GoogleAnalytics.ID) 68 69 }