summaryrefslogtreecommitdiffstats
path: root/deploy
diff options
context:
space:
mode:
authorRobert van Gent <rvangent@google.com>2019-05-31 09:55:48 -0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-05-31 22:08:12 +0200
commitb0f536fb276f63df0b0b8d92aeda80affb4b6a34 (patch)
tree616249222d6f07e56c7c71af6bce793d5a5939f0 /deploy
parent1384d77a04d7027d719993c6f54f892b5e7974db (diff)
Drop dashes in http header matcher attributes; other changes from code review
Diffstat (limited to 'deploy')
-rw-r--r--deploy/deployConfig.go6
-rw-r--r--deploy/deployConfig_test.go89
2 files changed, 57 insertions, 38 deletions
diff --git a/deploy/deployConfig.go b/deploy/deployConfig.go
index b4fa325b7..0ea675b82 100644
--- a/deploy/deployConfig.go
+++ b/deploy/deployConfig.go
@@ -48,15 +48,15 @@ type matcher struct {
// CacheControl specifies caching attributes to use when serving the blob.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
- CacheControl string `mapstructure:"Cache-Control"`
+ CacheControl string
// ContentEncoding specifies the encoding used for the blob's content, if any.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
- ContentEncoding string `mapstructure:"Content-Encoding"`
+ ContentEncoding string
// ContentType specifies the MIME type of the blob being written.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
- ContentType string `mapstructure:"Content-Type"`
+ ContentType string
// Gzip determines whether the file should be gzipped before upload.
// If so, the ContentEncoding field will automatically be set to "gzip".
diff --git a/deploy/deployConfig_test.go b/deploy/deployConfig_test.go
index 3f849d89c..47e9e1e44 100644
--- a/deploy/deployConfig_test.go
+++ b/deploy/deployConfig_test.go
@@ -14,6 +14,7 @@
package deploy
import (
+ "fmt"
"testing"
"github.com/gohugoio/hugo/config"
@@ -32,29 +33,48 @@ someOtherValue = "foo"
order = ["o1", "o2"]
+# All lowercase.
[[deployment.targets]]
-Name = "name1"
+name = "name0"
+url = "url0"
+cloudfrontdistributionid = "cdn0"
+
+# All uppercase.
+[[deployment.targets]]
+NAME = "name1"
URL = "url1"
-CloudFrontDistributionID = "cdn1"
+CLOUDFRONTDISTRIBUTIONID = "cdn1"
+# Camelcase.
[[deployment.targets]]
name = "name2"
url = "url2"
-cloudfrontdistributionid = "cdn2"
+cloudFrontDistributionID = "cdn2"
+# All lowercase.
[[deployment.matchers]]
-Pattern = "^pattern1$"
-Cache-Control = "cachecontrol1"
-Content-Encoding = "contentencoding1"
-Content-Type = "contenttype1"
-Gzip = true
-Force = true
+pattern = "^pattern0$"
+cachecontrol = "cachecontrol0"
+contentencoding = "contentencoding0"
+contenttype = "contenttype0"
+# All uppercase.
+[[deployment.matchers]]
+PATTERN = "^pattern1$"
+CACHECONTROL = "cachecontrol1"
+CONTENTENCODING = "contentencoding1"
+CONTENTTYPE = "contenttype1"
+GZIP = true
+FORCE = true
+
+# Camelcase.
[[deployment.matchers]]
pattern = "^pattern2$"
-cache-control = "cachecontrol2"
-content-encoding = "contentencoding2"
-content-type = "contenttype2"
+cacheControl = "cachecontrol2"
+contentEncoding = "contentencoding2"
+contentType = "contenttype2"
+gzip = true
+force = true
`
cfg, err := config.FromConfigString(tomlConfig, "toml")
assert.NoError(err)
@@ -62,34 +82,33 @@ content-type = "contenttype2"
dcfg, err := decodeConfig(cfg)
assert.NoError(err)
+ // Order.
assert.Equal(2, len(dcfg.Order))
assert.Equal("o1", dcfg.Order[0])
assert.Equal("o2", dcfg.Order[1])
assert.Equal(2, len(dcfg.ordering))
- assert.Equal(2, len(dcfg.Targets))
- assert.Equal("name1", dcfg.Targets[0].Name)
- assert.Equal("url1", dcfg.Targets[0].URL)
- assert.Equal("cdn1", dcfg.Targets[0].CloudFrontDistributionID)
- assert.Equal("name2", dcfg.Targets[1].Name)
- assert.Equal("url2", dcfg.Targets[1].URL)
- assert.Equal("cdn2", dcfg.Targets[1].CloudFrontDistributionID)
-
- assert.Equal(2, len(dcfg.Matchers))
- assert.Equal("^pattern1$", dcfg.Matchers[0].Pattern)
- assert.NotNil(dcfg.Matchers[0].re)
- assert.Equal("cachecontrol1", dcfg.Matchers[0].CacheControl)
- assert.Equal("contentencoding1", dcfg.Matchers[0].ContentEncoding)
- assert.Equal("contenttype1", dcfg.Matchers[0].ContentType)
- assert.True(dcfg.Matchers[0].Gzip)
- assert.True(dcfg.Matchers[0].Force)
- assert.Equal("^pattern2$", dcfg.Matchers[1].Pattern)
- assert.NotNil(dcfg.Matchers[1].re)
- assert.Equal("cachecontrol2", dcfg.Matchers[1].CacheControl)
- assert.Equal("contentencoding2", dcfg.Matchers[1].ContentEncoding)
- assert.Equal("contenttype2", dcfg.Matchers[1].ContentType)
- assert.False(dcfg.Matchers[1].Gzip)
- assert.False(dcfg.Matchers[1].Force)
+ // Targets.
+ assert.Equal(3, len(dcfg.Targets))
+ for i := 0; i < 3; i++ {
+ tgt := dcfg.Targets[i]
+ assert.Equal(fmt.Sprintf("name%d", i), tgt.Name)
+ assert.Equal(fmt.Sprintf("url%d", i), tgt.URL)
+ assert.Equal(fmt.Sprintf("cdn%d", i), tgt.CloudFrontDistributionID)
+ }
+
+ // Matchers.
+ assert.Equal(3, len(dcfg.Matchers))
+ for i := 0; i < 3; i++ {
+ m := dcfg.Matchers[i]
+ assert.Equal(fmt.Sprintf("^pattern%d$", i), m.Pattern)
+ assert.NotNil(m.re)
+ assert.Equal(fmt.Sprintf("cachecontrol%d", i), m.CacheControl)
+ assert.Equal(fmt.Sprintf("contentencoding%d", i), m.ContentEncoding)
+ assert.Equal(fmt.Sprintf("contenttype%d", i), m.ContentType)
+ assert.Equal(i != 0, m.Gzip)
+ assert.Equal(i != 0, m.Force)
+ }
}
func TestInvalidOrderingPattern(t *testing.T) {