From 2af0664603e56943a2c0db43175405270f4792b6 Mon Sep 17 00:00:00 2001 From: Keiko Oda Date: Thu, 13 Sep 2018 21:47:29 -0700 Subject: [PATCH] Save sha without original sha when to save in Hashed --- go/porcelain/deploy.go | 9 +++++++-- go/porcelain/deploy_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index d62f6585..19b22092 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -121,8 +121,13 @@ func newDeployFiles() *deployFiles { func (d *deployFiles) Add(p string, f *FileBundle) { d.Files[p] = f d.Sums[p] = f.Sum - list, _ := d.Hashed[f.Sum] - d.Hashed[f.Sum] = append(list, f) + // Remove ":original_sha" part when to save in Hashed (asset management) + sum := f.Sum + if strings.Contains(sum, ":") { + sum = strings.Split(sum, ":")[0] + } + list, _ := d.Hashed[sum] + d.Hashed[sum] = append(list, f) } func (n *Netlify) overCommitted(d *deployFiles) bool { diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go index c25fff90..0942cea1 100644 --- a/go/porcelain/deploy_test.go +++ b/go/porcelain/deploy_test.go @@ -24,3 +24,30 @@ func TestGetAssetManagementSha(t *testing.T) { } } } + +func TestAddWithAssetManagement(t *testing.T) { + files := newDeployFiles() + tests := []struct { + rel string + sum string + }{ + {"foo.jpg", "sum1"}, + {"bar.jpg", "sum2"}, + {"baz.jpg", "sum3:originalsha"}, + } + + for _, test := range tests { + file := &FileBundle{} + file.Sum = test.sum + files.Add(test.rel, file) + } + + out := files.Hashed["sum3"] + if len(out) != 1 { + t.Fatalf("expected `%d`, got `%d`", 1, len(out)) + } + out2 := files.Sums["baz.jpg"] + if out2 != "sum3:originalsha" { + t.Fatalf("expected `%v`, got `%v`", "sum3:originalsha", out2) + } +}