aboutsummaryrefslogtreecommitdiffhomepage
path: root/deploy/deploy_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/deploy_test.go')
-rw-r--r--deploy/deploy_test.go58
1 files changed, 27 insertions, 31 deletions
diff --git a/deploy/deploy_test.go b/deploy/deploy_test.go
index 5c436abf2..fe874fbbd 100644
--- a/deploy/deploy_test.go
+++ b/deploy/deploy_test.go
@@ -108,7 +108,7 @@ func TestFindDiffs(t *testing.T) {
{
Description: "local == remote with route.Force true -> diffs",
Local: []*localFile{
- {NativePath: "aaa", SlashPath: "aaa", UploadSize: 1, matcher: &matcher{Force: true}, md5: hash1},
+ {NativePath: "aaa", SlashPath: "aaa", UploadSize: 1, matcher: &Matcher{Force: true}, md5: hash1},
makeLocal("bbb", 2, hash1),
},
Remote: []*blob.ListObject{
@@ -289,8 +289,8 @@ func TestLocalFile(t *testing.T) {
tests := []struct {
Description string
Path string
- Matcher *matcher
- MediaTypesConfig []map[string]any
+ Matcher *Matcher
+ MediaTypesConfig map[string]any
WantContent []byte
WantSize int64
WantMD5 []byte
@@ -315,7 +315,7 @@ func TestLocalFile(t *testing.T) {
{
Description: "CacheControl from matcher",
Path: "foo.txt",
- Matcher: &matcher{CacheControl: "max-age=630720000"},
+ Matcher: &Matcher{CacheControl: "max-age=630720000"},
WantContent: contentBytes,
WantSize: contentLen,
WantMD5: contentMD5[:],
@@ -324,7 +324,7 @@ func TestLocalFile(t *testing.T) {
{
Description: "ContentEncoding from matcher",
Path: "foo.txt",
- Matcher: &matcher{ContentEncoding: "foobar"},
+ Matcher: &Matcher{ContentEncoding: "foobar"},
WantContent: contentBytes,
WantSize: contentLen,
WantMD5: contentMD5[:],
@@ -333,7 +333,7 @@ func TestLocalFile(t *testing.T) {
{
Description: "ContentType from matcher",
Path: "foo.txt",
- Matcher: &matcher{ContentType: "foo/bar"},
+ Matcher: &Matcher{ContentType: "foo/bar"},
WantContent: contentBytes,
WantSize: contentLen,
WantMD5: contentMD5[:],
@@ -342,7 +342,7 @@ func TestLocalFile(t *testing.T) {
{
Description: "gzipped content",
Path: "foo.txt",
- Matcher: &matcher{Gzip: true},
+ Matcher: &Matcher{Gzip: true},
WantContent: gzBytes,
WantSize: gzLen,
WantMD5: gzMD5[:],
@@ -351,11 +351,9 @@ func TestLocalFile(t *testing.T) {
{
Description: "Custom MediaType",
Path: "foo.hugo",
- MediaTypesConfig: []map[string]any{
- {
- "hugo/custom": map[string]any{
- "suffixes": []string{"hugo"},
- },
+ MediaTypesConfig: map[string]any{
+ "hugo/custom": map[string]any{
+ "suffixes": []string{"hugo"},
},
},
WantContent: contentBytes,
@@ -373,11 +371,11 @@ func TestLocalFile(t *testing.T) {
}
mediaTypes := media.DefaultTypes
if len(tc.MediaTypesConfig) > 0 {
- mt, err := media.DecodeTypes(tc.MediaTypesConfig...)
+ mt, err := media.DecodeTypes(tc.MediaTypesConfig)
if err != nil {
t.Fatal(err)
}
- mediaTypes = mt
+ mediaTypes = mt.Config
}
lf, err := newLocalFile(fs, tc.Path, filepath.ToSlash(tc.Path), tc.Matcher, mediaTypes)
if err != nil {
@@ -556,9 +554,9 @@ func TestEndToEndSync(t *testing.T) {
}
deployer := &Deployer{
localFs: test.fs,
- maxDeletes: -1,
bucket: test.bucket,
mediaTypes: media.DefaultTypes,
+ cfg: DeployConfig{MaxDeletes: -1},
}
// Initial deployment should sync remote with local.
@@ -639,9 +637,9 @@ func TestMaxDeletes(t *testing.T) {
}
deployer := &Deployer{
localFs: test.fs,
- maxDeletes: -1,
bucket: test.bucket,
mediaTypes: media.DefaultTypes,
+ cfg: DeployConfig{MaxDeletes: -1},
}
// Sync remote with local.
@@ -662,7 +660,7 @@ func TestMaxDeletes(t *testing.T) {
}
// A deployment with maxDeletes=0 shouldn't change anything.
- deployer.maxDeletes = 0
+ deployer.cfg.MaxDeletes = 0
if err := deployer.Deploy(ctx); err != nil {
t.Errorf("deploy failed: %v", err)
}
@@ -672,7 +670,7 @@ func TestMaxDeletes(t *testing.T) {
}
// A deployment with maxDeletes=1 shouldn't change anything either.
- deployer.maxDeletes = 1
+ deployer.cfg.MaxDeletes = 1
if err := deployer.Deploy(ctx); err != nil {
t.Errorf("deploy failed: %v", err)
}
@@ -682,7 +680,7 @@ func TestMaxDeletes(t *testing.T) {
}
// A deployment with maxDeletes=2 should make the changes.
- deployer.maxDeletes = 2
+ deployer.cfg.MaxDeletes = 2
if err := deployer.Deploy(ctx); err != nil {
t.Errorf("deploy failed: %v", err)
}
@@ -700,7 +698,7 @@ func TestMaxDeletes(t *testing.T) {
}
// A deployment with maxDeletes=-1 should make the changes.
- deployer.maxDeletes = -1
+ deployer.cfg.MaxDeletes = -1
if err := deployer.Deploy(ctx); err != nil {
t.Errorf("deploy failed: %v", err)
}
@@ -762,7 +760,7 @@ func TestIncludeExclude(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- tgt := &target{
+ tgt := &Target{
Include: test.Include,
Exclude: test.Exclude,
}
@@ -770,9 +768,8 @@ func TestIncludeExclude(t *testing.T) {
t.Error(err)
}
deployer := &Deployer{
- localFs: fsTest.fs,
- maxDeletes: -1,
- bucket: fsTest.bucket,
+ localFs: fsTest.fs,
+ cfg: DeployConfig{MaxDeletes: -1}, bucket: fsTest.bucket,
target: tgt,
mediaTypes: media.DefaultTypes,
}
@@ -828,9 +825,8 @@ func TestIncludeExcludeRemoteDelete(t *testing.T) {
t.Fatal(err)
}
deployer := &Deployer{
- localFs: fsTest.fs,
- maxDeletes: -1,
- bucket: fsTest.bucket,
+ localFs: fsTest.fs,
+ cfg: DeployConfig{MaxDeletes: -1}, bucket: fsTest.bucket,
mediaTypes: media.DefaultTypes,
}
@@ -848,7 +844,7 @@ func TestIncludeExcludeRemoteDelete(t *testing.T) {
}
// Second sync
- tgt := &target{
+ tgt := &Target{
Include: test.Include,
Exclude: test.Exclude,
}
@@ -882,7 +878,7 @@ func TestCompression(t *testing.T) {
deployer := &Deployer{
localFs: test.fs,
bucket: test.bucket,
- matchers: []*matcher{{Pattern: ".*", Gzip: true, re: regexp.MustCompile(".*")}},
+ cfg: DeployConfig{MaxDeletes: -1, Matchers: []*Matcher{{Pattern: ".*", Gzip: true, re: regexp.MustCompile(".*")}}},
mediaTypes: media.DefaultTypes,
}
@@ -937,7 +933,7 @@ func TestMatching(t *testing.T) {
deployer := &Deployer{
localFs: test.fs,
bucket: test.bucket,
- matchers: []*matcher{{Pattern: "^subdir/aaa$", Force: true, re: regexp.MustCompile("^subdir/aaa$")}},
+ cfg: DeployConfig{MaxDeletes: -1, Matchers: []*Matcher{{Pattern: "^subdir/aaa$", Force: true, re: regexp.MustCompile("^subdir/aaa$")}}},
mediaTypes: media.DefaultTypes,
}
@@ -962,7 +958,7 @@ func TestMatching(t *testing.T) {
}
// Repeat with a matcher that should now match 3 files.
- deployer.matchers = []*matcher{{Pattern: "aaa", Force: true, re: regexp.MustCompile("aaa")}}
+ deployer.cfg.Matchers = []*Matcher{{Pattern: "aaa", Force: true, re: regexp.MustCompile("aaa")}}
if err := deployer.Deploy(ctx); err != nil {
t.Errorf("no-op deploy with triple force matcher: %v", err)
}