Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 0584d8c

Browse files
committedJun 21, 2017
dep: add TestCalculatePrune
Add a test for dep.calculatePrune Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent c79b048 commit 0584d8c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
 

‎txn_writer_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88
"io/ioutil"
99
"os"
1010
"path/filepath"
11+
"sort"
1112
"strings"
1213
"testing"
1314

15+
"reflect"
16+
1417
"github.com/golang/dep/internal/test"
1518
"github.com/pkg/errors"
1619
)
@@ -567,3 +570,37 @@ func TestSafeWriter_VendorDotGitPreservedWithForceVendor(t *testing.T) {
567570
t.Fatal(err)
568571
}
569572
}
573+
574+
func TestCalculatePrune(t *testing.T) {
575+
h := test.NewHelper(t)
576+
defer h.Cleanup()
577+
578+
vendorDir := "vendor"
579+
h.TempDir(vendorDir)
580+
h.TempDir(filepath.Join(vendorDir, "github.com", "prune", "package"))
581+
h.TempDir(filepath.Join(vendorDir, "github.com", "keep", "package"))
582+
583+
toKeep := []string{
584+
"github.com/keep/package",
585+
}
586+
587+
got, err := calculatePrune(h.Path(vendorDir), toKeep, nil)
588+
if err != nil {
589+
t.Fatal(err)
590+
}
591+
592+
sort.Sort(byLen(got))
593+
594+
if len(got) != 2 {
595+
t.Fatalf("expected 2 directories, got %v", len(got))
596+
}
597+
598+
want := []string{
599+
h.Path(filepath.Join(vendorDir, "github.com", "prune", "package")),
600+
h.Path(filepath.Join(vendorDir, "github.com", "prune")),
601+
}
602+
603+
if !reflect.DeepEqual(want, got) {
604+
t.Fatalf("expect %s, got %s", want, got)
605+
}
606+
}

0 commit comments

Comments
 (0)
This repository has been archived.