github.com/jbramsden/hugo@v0.47.1/config/privacy/privacyConfig_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 privacy 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 [privacy] 32 [privacy.disqus] 33 disable = true 34 [privacy.googleAnalytics] 35 disable = true 36 respectDoNotTrack = true 37 anonymizeIP = true 38 useSessionStorage = true 39 [privacy.instagram] 40 disable = true 41 simple = true 42 [privacy.twitter] 43 disable = true 44 enableDNT = true 45 simple = true 46 [privacy.vimeo] 47 disable = true 48 simple = true 49 [privacy.youtube] 50 disable = true 51 privacyEnhanced = true 52 simple = true 53 ` 54 cfg, err := config.FromConfigString(tomlConfig, "toml") 55 assert.NoError(err) 56 57 pc, err := DecodeConfig(cfg) 58 assert.NoError(err) 59 assert.NotNil(pc) 60 61 assert.True(pc.Disqus.Disable) 62 assert.True(pc.GoogleAnalytics.Disable) 63 assert.True(pc.GoogleAnalytics.RespectDoNotTrack) 64 assert.True(pc.GoogleAnalytics.AnonymizeIP) 65 assert.True(pc.GoogleAnalytics.UseSessionStorage) 66 assert.True(pc.Instagram.Disable) 67 assert.True(pc.Instagram.Simple) 68 assert.True(pc.Twitter.Disable) 69 assert.True(pc.Twitter.EnableDNT) 70 assert.True(pc.Twitter.Simple) 71 assert.True(pc.Vimeo.Disable) 72 assert.True(pc.Vimeo.Simple) 73 assert.True(pc.YouTube.PrivacyEnhanced) 74 assert.True(pc.YouTube.Disable) 75 } 76 77 func TestDecodeConfigFromTOMLCaseInsensitive(t *testing.T) { 78 assert := require.New(t) 79 80 tomlConfig := ` 81 82 someOtherValue = "foo" 83 84 [Privacy] 85 [Privacy.YouTube] 86 PrivacyENhanced = true 87 ` 88 cfg, err := config.FromConfigString(tomlConfig, "toml") 89 assert.NoError(err) 90 91 pc, err := DecodeConfig(cfg) 92 assert.NoError(err) 93 assert.NotNil(pc) 94 assert.True(pc.YouTube.PrivacyEnhanced) 95 } 96 97 func TestDecodeConfigDefault(t *testing.T) { 98 assert := require.New(t) 99 100 pc, err := DecodeConfig(viper.New()) 101 assert.NoError(err) 102 assert.NotNil(pc) 103 assert.False(pc.YouTube.PrivacyEnhanced) 104 }