deploy: Implement include/exclude filters for deploy

Fixes #6922
This commit is contained in:
Robert van Gent
2020-02-26 22:26:05 -08:00
committed by GitHub
parent 33ae621083
commit 05a74eaec0
5 changed files with 151 additions and 5 deletions

View File

@@ -640,6 +640,86 @@ func TestMaxDeletes(t *testing.T) {
}
}
// TestIncludeExclude verifies that the include/exclude options for targets work.
func TestIncludeExclude(t *testing.T) {
ctx := context.Background()
tests := []struct {
Include string
Exclude string
Want deploySummary
}{
{
Want: deploySummary{NumLocal: 5, NumUploads: 5},
},
{
Include: "**aaa",
Want: deploySummary{NumLocal: 3, NumUploads: 3},
},
{
Include: "**bbb",
Want: deploySummary{NumLocal: 2, NumUploads: 2},
},
{
Include: "aaa",
Want: deploySummary{NumLocal: 1, NumUploads: 1},
},
{
Exclude: "**aaa",
Want: deploySummary{NumLocal: 2, NumUploads: 2},
},
{
Exclude: "**bbb",
Want: deploySummary{NumLocal: 3, NumUploads: 3},
},
{
Exclude: "aaa",
Want: deploySummary{NumLocal: 4, NumUploads: 4},
},
{
Include: "**aaa",
Exclude: "**nested**",
Want: deploySummary{NumLocal: 2, NumUploads: 2},
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("include %q exclude %q", test.Include, test.Exclude), func(t *testing.T) {
fsTests, cleanup, err := initFsTests()
if err != nil {
t.Fatal(err)
}
defer cleanup()
fsTest := fsTests[1] // just do file-based test
_, err = initLocalFs(ctx, fsTest.fs)
if err != nil {
t.Fatal(err)
}
tgt := &target{
Include: test.Include,
Exclude: test.Exclude,
}
if err := tgt.parseIncludeExclude(); err != nil {
t.Error(err)
}
deployer := &Deployer{
localFs: fsTest.fs,
maxDeletes: -1,
bucket: fsTest.bucket,
target: tgt,
}
// Sync remote with local.
if err := deployer.Deploy(ctx); err != nil {
t.Errorf("deploy: failed: %v", err)
}
if !cmp.Equal(deployer.summary, test.Want) {
t.Errorf("deploy: got %v, want %v", deployer.summary, test.Want)
}
})
}
}
// TestCompression verifies that gzip compression works correctly.
// In particular, MD5 hashes must be of the compressed content.
func TestCompression(t *testing.T) {