privacyConfig_test.go (2450B)
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 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 [privacy] 31 [privacy.disqus] 32 disable = true 33 [privacy.googleAnalytics] 34 disable = true 35 respectDoNotTrack = true 36 anonymizeIP = true 37 useSessionStorage = true 38 [privacy.instagram] 39 disable = true 40 simple = true 41 [privacy.twitter] 42 disable = true 43 enableDNT = true 44 simple = true 45 [privacy.vimeo] 46 disable = true 47 enableDNT = 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 c.Assert(err, qt.IsNil) 56 57 pc, err := DecodeConfig(cfg) 58 c.Assert(err, qt.IsNil) 59 c.Assert(pc, qt.Not(qt.IsNil)) 60 61 got := []bool{ 62 pc.Disqus.Disable, pc.GoogleAnalytics.Disable, 63 pc.GoogleAnalytics.RespectDoNotTrack, pc.GoogleAnalytics.AnonymizeIP, 64 pc.GoogleAnalytics.UseSessionStorage, pc.Instagram.Disable, 65 pc.Instagram.Simple, pc.Twitter.Disable, pc.Twitter.EnableDNT, 66 pc.Twitter.Simple, pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple, 67 pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable, 68 } 69 70 c.Assert(got, qt.All(qt.Equals), true) 71 } 72 73 func TestDecodeConfigFromTOMLCaseInsensitive(t *testing.T) { 74 c := qt.New(t) 75 76 tomlConfig := ` 77 78 someOtherValue = "foo" 79 80 [Privacy] 81 [Privacy.YouTube] 82 PrivacyENhanced = true 83 ` 84 cfg, err := config.FromConfigString(tomlConfig, "toml") 85 c.Assert(err, qt.IsNil) 86 87 pc, err := DecodeConfig(cfg) 88 c.Assert(err, qt.IsNil) 89 c.Assert(pc, qt.Not(qt.IsNil)) 90 c.Assert(pc.YouTube.PrivacyEnhanced, qt.Equals, true) 91 } 92 93 func TestDecodeConfigDefault(t *testing.T) { 94 c := qt.New(t) 95 96 pc, err := DecodeConfig(config.New()) 97 c.Assert(err, qt.IsNil) 98 c.Assert(pc, qt.Not(qt.IsNil)) 99 c.Assert(pc.YouTube.PrivacyEnhanced, qt.Equals, false) 100 }