| 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 |
[privacy.instagram] |
| 37 |
disable = true |
| 38 |
simple = true |
| 39 |
[privacy.x] |
| 40 |
disable = true |
| 41 |
enableDNT = true |
| 42 |
simple = true |
| 43 |
[privacy.vimeo] |
| 44 |
disable = true |
| 45 |
enableDNT = true |
| 46 |
simple = true |
| 47 |
[privacy.youtube] |
| 48 |
disable = true |
| 49 |
privacyEnhanced = true |
| 50 |
simple = true |
| 51 |
` |
| 52 |
cfg, err := config.FromConfigString(tomlConfig, "toml") |
| 53 |
c.Assert(err, qt.IsNil) |
| 54 |
|
| 55 |
pc, err := DecodeConfig(cfg) |
| 56 |
c.Assert(err, qt.IsNil) |
| 57 |
c.Assert(pc, qt.Not(qt.IsNil)) |
| 58 |
|
| 59 |
got := []bool{ |
| 60 |
pc.Disqus.Disable, pc.GoogleAnalytics.Disable, |
| 61 |
pc.GoogleAnalytics.RespectDoNotTrack, pc.Instagram.Disable, |
| 62 |
pc.Instagram.Simple, |
| 63 |
pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple, |
| 64 |
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable, pc.X.Disable, pc.X.EnableDNT, |
| 65 |
pc.X.Simple, |
| 66 |
} |
| 67 |
|
| 68 |
c.Assert(got, qt.All(qt.Equals), true) |
| 69 |
} |
| 70 |
|
| 71 |
func TestDecodeConfigFromTOMLCaseInsensitive(t *testing.T) { |
| 72 |
c := qt.New(t) |
| 73 |
|
| 74 |
tomlConfig := ` |
| 75 |
|
| 76 |
someOtherValue = "foo" |
| 77 |
|
| 78 |
[Privacy] |
| 79 |
[Privacy.YouTube] |
| 80 |
PrivacyENhanced = true |
| 81 |
` |
| 82 |
cfg, err := config.FromConfigString(tomlConfig, "toml") |
| 83 |
c.Assert(err, qt.IsNil) |
| 84 |
|
| 85 |
pc, err := DecodeConfig(cfg) |
| 86 |
c.Assert(err, qt.IsNil) |
| 87 |
c.Assert(pc, qt.Not(qt.IsNil)) |
| 88 |
c.Assert(pc.YouTube.PrivacyEnhanced, qt.Equals, true) |
| 89 |
} |
| 90 |
|
| 91 |
func TestDecodeConfigDefault(t *testing.T) { |
| 92 |
c := qt.New(t) |
| 93 |
|
| 94 |
pc, err := DecodeConfig(config.New()) |
| 95 |
c.Assert(err, qt.IsNil) |
| 96 |
c.Assert(pc, qt.Not(qt.IsNil)) |
| 97 |
c.Assert(pc.YouTube.PrivacyEnhanced, qt.Equals, false) |
| 98 |
} |