diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-12 02:22:08 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-12 02:22:08 +0200 |
commit | d57f90b78eeb6b09b15e3fe57609ede66df4edac (patch) | |
tree | 961aa929391c0e804f32d26016f9e385f6e70ecb | |
parent | 58fe211f1b0e4863b425542d2fad15803276fd66 (diff) | |
download | go-git-d57f90b78eeb6b09b15e3fe57609ede66df4edac.tar.gz |
fixtures: new fixture package being use in all packages
-rw-r--r-- | blame_test.go | 53 | ||||
-rw-r--r-- | common_test.go | 65 | ||||
-rw-r--r-- | file_test.go | 49 | ||||
-rw-r--r-- | fixtures/fixtures.go | 65 | ||||
-rw-r--r-- | formats/idxfile/decoder_test.go | 6 | ||||
-rw-r--r-- | formats/idxfile/encoder_test.go | 4 | ||||
-rw-r--r-- | formats/packfile/decoder_test.go | 37 | ||||
-rw-r--r-- | formats/packfile/scanner_test.go | 8 | ||||
-rw-r--r-- | objects_test.go | 18 | ||||
-rw-r--r-- | references_test.go | 40 | ||||
-rw-r--r-- | repository.go | 34 | ||||
-rw-r--r-- | repository_test.go | 89 | ||||
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit_test.go | 42 | ||||
-rw-r--r-- | storage/filesystem/object_test.go | 8 | ||||
-rw-r--r-- | tag.go | 2 | ||||
-rw-r--r-- | tag_test.go | 36 | ||||
-rw-r--r-- | tree_walker_test.go | 141 |
17 files changed, 293 insertions, 404 deletions
diff --git a/blame_test.go b/blame_test.go index c4cdc85..9cf8992 100644 --- a/blame_test.go +++ b/blame_test.go @@ -1,39 +1,16 @@ package git import ( - "os" - "gopkg.in/src-d/go-git.v4/core" - "gopkg.in/src-d/go-git.v4/formats/packfile" . "gopkg.in/check.v1" ) -type BlameCommon struct { - repos map[string]*Repository +type BlameSuite struct { + BaseSuite } -var _ = Suite(&BlameCommon{}) - -// create the repositories of the fixtures -func (s *BlameCommon) SetUpSuite(c *C) { - s.repos = make(map[string]*Repository, 0) - for _, fixRepo := range fixtureRepos { - r := NewMemoryRepository() - - f, err := os.Open(fixRepo.packfile) - c.Assert(err, IsNil) - - stream := packfile.NewScanner(f) - - d := packfile.NewDecoder(stream, r.s.ObjectStorage()) - _, err = d.Decode() - c.Assert(err, IsNil) - c.Assert(f.Close(), IsNil) - - s.repos[fixRepo.url] = r - } -} +var _ = Suite(&BlameSuite{}) type blameTest struct { repo string @@ -42,8 +19,8 @@ type blameTest struct { blames []string // the commits blamed for each line } -func (s *BlameCommon) mockBlame(t blameTest, c *C) (blame *Blame) { - r, ok := s.repos[t.repo] +func (s *BlameSuite) mockBlame(t blameTest, c *C) (blame *Blame) { + r, ok := s.Repositories[t.repo] c.Assert(ok, Equals, true) commit, err := r.Commit(core.NewHash(t.rev)) @@ -75,11 +52,11 @@ func (s *BlameCommon) mockBlame(t blameTest, c *C) (blame *Blame) { } // run a blame on all the suite's tests -func (s *BlameCommon) TestBlame(c *C) { +func (s *BlameSuite) TestBlame(c *C) { for _, t := range blameTests { exp := s.mockBlame(t, c) - r, ok := s.repos[t.repo] + r, ok := s.Repositories[t.repo] c.Assert(ok, Equals, true) commit, err := r.Commit(core.NewHash(t.rev)) @@ -116,28 +93,28 @@ func concat(vargs ...[]string) []string { var blameTests = [...]blameTest{ // use the blame2humantest.bash script to easily add more tests. - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "binary.jpg", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "binary.jpg", concat( repeat("35e85108805c84807bc66a02d91535e1e24b38b9", 285), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG", concat( repeat("b8e471f58bcbca63b07bda20e428190409c2db47", 1), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "go/example.go", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "go/example.go", concat( repeat("918c48b83bd081e863dbe1b80f8998f058cd8294", 142), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/long.json", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/long.json", concat( repeat("af2d6a6954d532f8ffb47615169c8fdf9d383a1a", 6492), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/short.json", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/short.json", concat( repeat("af2d6a6954d532f8ffb47615169c8fdf9d383a1a", 22), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "LICENSE", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "LICENSE", concat( repeat("b029517f6300c2da0f4b651b8642506cd6aaf45d", 22), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "php/crappy.php", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "php/crappy.php", concat( repeat("918c48b83bd081e863dbe1b80f8998f058cd8294", 259), )}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "vendor/foo.go", concat( + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "vendor/foo.go", concat( repeat("6ecf0ef2c2dffb796033e5a02219af86ec6584e5", 7), )}, /* diff --git a/common_test.go b/common_test.go index 65c8664..d35abd3 100644 --- a/common_test.go +++ b/common_test.go @@ -9,7 +9,9 @@ import ( "gopkg.in/src-d/go-git.v4/clients" "gopkg.in/src-d/go-git.v4/clients/common" "gopkg.in/src-d/go-git.v4/core" + "gopkg.in/src-d/go-git.v4/fixtures" "gopkg.in/src-d/go-git.v4/formats/packfile" + "gopkg.in/src-d/go-git.v4/storage/filesystem" . "gopkg.in/check.v1" ) @@ -17,27 +19,51 @@ import ( func Test(t *testing.T) { TestingT(t) } type BaseSuite struct { - Repository *Repository + fixtures.Suite + + Repository *Repository + Repositories map[string]*Repository } func (s *BaseSuite) SetUpSuite(c *C) { + s.Suite.SetUpSuite(c) s.installMockProtocol(c) s.buildRepository(c) + s.buildRepositories(c) } func (s *BaseSuite) installMockProtocol(c *C) { - clients.InstallProtocol("mock", func(end common.Endpoint) common.GitUploadPackService { + clients.InstallProtocol("https", func(end common.Endpoint) common.GitUploadPackService { return &MockGitUploadPackService{endpoint: end} }) } func (s *BaseSuite) buildRepository(c *C) { - s.Repository = NewMemoryRepository() - err := s.Repository.Clone(&CloneOptions{URL: RepositoryFixture}) + f := fixtures.Basic().One() + + var err error + s.Repository, err = NewFilesystemRepository(f.DotGit().Base()) c.Assert(err, IsNil) } -const RepositoryFixture = "mock://formats/packfile/fixtures/git-fixture.ref-delta" +func (s *BaseSuite) buildRepositories(c *C) { + s.Repositories = make(map[string]*Repository, 0) + for _, fixture := range fixtures.All() { + r := NewMemoryRepository() + + f := fixture.Packfile() + defer f.Close() + + n := packfile.NewScanner(f) + d := packfile.NewDecoder(n, r.s.ObjectStorage()) + _, err := d.Decode() + c.Assert(err, IsNil) + + s.Repositories[fixture.URL] = r + } +} + +const RepositoryFixture = "https://github.com/git-fixtures/basic.git" type MockGitUploadPackService struct { connected bool @@ -84,11 +110,13 @@ func (p *MockGitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.Rea return nil, errors.New("not connected") } + f := fixtures.ByURL(p.endpoint.String()) + if len(r.Wants) == 1 { - return os.Open("formats/packfile/fixtures/git-fixture.ref-delta") + return f.Exclude("single-branch").One().Packfile(), nil } - return os.Open("fixtures/pack-63bbc2e1bde392e2205b30fa3584ddb14ef8bd41.pack") + return f.One().Packfile(), nil } func (p *MockGitUploadPackService) Disconnect() error { @@ -158,3 +186,26 @@ func (s *SuiteCommon) TestCountLines(c *C) { c.Assert(o, Equals, t.e, Commentf("subtest %d, input=%q", i, t.i)) } } + +func (s *BaseSuite) Clone(url string) *Repository { + r := NewMemoryRepository() + if err := r.Clone(&CloneOptions{URL: url}); err != nil { + panic(err) + } + + return r +} + +func (s *BaseSuite) NewRepository(f *fixtures.Fixture) *Repository { + storage, err := filesystem.NewStorage(f.DotGit()) + if err != nil { + panic(err) + } + + r, err := NewRepository(storage) + if err != nil { + panic(err) + } + + return r +} diff --git a/file_test.go b/file_test.go index e545d99..28449dd 100644 --- a/file_test.go +++ b/file_test.go @@ -8,23 +8,11 @@ import ( . "gopkg.in/check.v1" ) -type SuiteFile struct { +type FileSuite struct { BaseSuite - repos map[string]*Repository } -var _ = Suite(&SuiteFile{}) - -// create the repositories of the fixtures -func (s *SuiteFile) SetUpSuite(c *C) { - s.BaseSuite.SetUpSuite(c) - - fileFixtures := []packedFixture{ - {"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"}, - {"https://github.com/cpcs499/Final_Pres_P", "formats/packfile/fixtures/Final_Pres_P.ofs-delta"}, - } - s.repos = unpackFixtures(c, fileFixtures) -} +var _ = Suite(&FileSuite{}) type fileIterExpectedEntry struct { Name string @@ -37,7 +25,7 @@ var fileIterTests = []struct { files []fileIterExpectedEntry }{ // https://api.github.com/repos/tyba/git-fixture/git/trees/6ecf0ef2c2dffb796033e5a02219af86ec6584e5 - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", []fileIterExpectedEntry{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", []fileIterExpectedEntry{ {".gitignore", "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88"}, {"CHANGELOG", "d3ff53e0564a9f87d8e84b6e28e5060e517008aa"}, {"LICENSE", "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f"}, @@ -50,9 +38,9 @@ var fileIterTests = []struct { }}, } -func (s *SuiteFile) TestIter(c *C) { +func (s *FileSuite) TestIter(c *C) { for i, t := range fileIterTests { - r := s.repos[t.repo] + r := s.Repositories[t.repo] commit, err := r.Commit(core.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) @@ -82,7 +70,7 @@ var contentsTests = []struct { contents string // expected contents of the file }{ { - "https://github.com/tyba/git-fixture.git", + "https://github.com/git-fixtures/basic.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", ".gitignore", `*.class @@ -100,7 +88,7 @@ hs_err_pid* `, }, { - "https://github.com/tyba/git-fixture.git", + "https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG", `Initial changelog @@ -108,9 +96,9 @@ hs_err_pid* }, } -func (s *SuiteFile) TestContents(c *C) { +func (s *FileSuite) TestContents(c *C) { for i, t := range contentsTests { - commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit)) + commit, err := s.Repositories[t.repo].Commit(core.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) file, err := commit.File(t.path) @@ -129,7 +117,7 @@ var linesTests = []struct { lines []string // expected lines in the file }{ { - "https://github.com/tyba/git-fixture.git", + "https://github.com/git-fixtures/basic.git", "b029517f6300c2da0f4b651b8642506cd6aaf45d", ".gitignore", []string{ @@ -148,7 +136,7 @@ var linesTests = []struct { }, }, { - "https://github.com/tyba/git-fixture.git", + "https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG", []string{ @@ -157,9 +145,12 @@ var linesTests = []struct { }, } -func (s *SuiteFile) TestLines(c *C) { +func (s *FileSuite) TestLines(c *C) { for i, t := range linesTests { - commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit)) + r, ok := s.Repositories[t.repo] + c.Assert(ok, Equals, true, Commentf("cannot find repository %s", t.repo)) + + commit, err := r.Commit(core.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) file, err := commit.File(t.path) @@ -176,7 +167,7 @@ var ignoreEmptyDirEntriesTests = []struct { commit string // the commit to search for the file }{ { - "https://github.com/cpcs499/Final_Pres_P", + "https://github.com/cpcs499/Final_Pres_P.git", "70bade703ce556c2c7391a8065c45c943e8b6bc3", // the Final dir in this commit is empty }, @@ -187,9 +178,9 @@ var ignoreEmptyDirEntriesTests = []struct { // // At least this test has a high chance of panicking if // we don't ignore empty dirs. -func (s *SuiteFile) TestIgnoreEmptyDirEntries(c *C) { +func (s *FileSuite) TestIgnoreEmptyDirEntries(c *C) { for i, t := range ignoreEmptyDirEntriesTests { - commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit)) + commit, err := s.Repositories[t.repo].Commit(core.NewHash(t.commit)) c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) tree, err := commit.Tree() @@ -204,7 +195,7 @@ func (s *SuiteFile) TestIgnoreEmptyDirEntries(c *C) { } } -func (s *SuiteFile) TestFileIter(c *C) { +func (s *FileSuite) TestFileIter(c *C) { hash := core.NewHash("1669dce138d9b841a518c64b10914d88f5e488ea") commit, err := s.Repository.Commit(hash) diff --git a/fixtures/fixtures.go b/fixtures/fixtures.go index 8e1c0ed..db0db96 100644 --- a/fixtures/fixtures.go +++ b/fixtures/fixtures.go @@ -2,13 +2,13 @@ package fixtures import ( "fmt" - "io" + "go/build" "os" "path/filepath" "github.com/alcortesm/tgz" - check "gopkg.in/check.v1" + "gopkg.in/check.v1" "gopkg.in/src-d/go-git.v4/core" "gopkg.in/src-d/go-git.v4/utils/fs" ) @@ -21,28 +21,47 @@ var folders []string var fixtures = Fixtures{{ Tags: []string{"packfile", "ofs-delta", ".git"}, - URL: "https://github.com/git-fixtures/basic", + URL: "https://github.com/git-fixtures/basic.git", Head: core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), PackfileHash: core.NewHash("a3fed42da1e8189a077c0e6846c040dcf73fc9dd"), DotGitHash: core.NewHash("0a00a25543e6d732dbf4e8e9fec55c8e65fc4e8d"), ObjectsCount: 31, }, { Tags: []string{"packfile", "ref-delta", ".git"}, - URL: "https://github.com/git-fixtures/basic", + URL: "https://github.com/git-fixtures/basic.git", Head: core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), PackfileHash: core.NewHash("c544593473465e6315ad4182d04d366c4592b829"), DotGitHash: core.NewHash("7cbde0ca02f13aedd5ec8b358ca17b1c0bf5ee64"), ObjectsCount: 31, }, { - Tags: []string{".git", "unpacked", "multi-packfile"}, + Tags: []string{"packfile", "ofs-delta", ".git", "single-branch"}, + URL: "https://github.com/git-fixtures/basic.git", + Head: core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), + PackfileHash: core.NewHash("61f0ee9c75af1f9678e6f76ff39fbe372b6f1c45"), + DotGitHash: core.NewHash("21504f6d2cc2ef0c9d6ebb8802c7b49abae40c1a"), + ObjectsCount: 28, +}, { + Tags: []string{"packfile", ".git", "unpacked", "multi-packfile"}, URL: "https://github.com/src-d/go-git.git", + Head: core.NewHash("e8788ad9165781196e917292d6055cba1d78664e"), + PackfileHash: core.NewHash("3559b3b47e695b33b0913237a4df3357e739831c"), DotGitHash: core.NewHash("174be6bd4292c18160542ae6dc6704b877b8a01a"), ObjectsCount: 2133, }, { Tags: []string{"packfile"}, - URL: "https://github.com/spinnaker/spinnaker", + URL: "https://github.com/spinnaker/spinnaker.git", Head: core.NewHash("06ce06d0fc49646c4de733c45b7788aabad98a6f"), PackfileHash: core.NewHash("f2e0a8889a746f7600e07d2246a2e29a72f696be"), +}, { + Tags: []string{"packfile"}, + URL: "https://github.com/jamesob/desk.git", + Head: core.NewHash("d2313db6e7ca7bac79b819d767b2a1449abb0a5d"), + PackfileHash: core.NewHash("4ec6344877f494690fc800aceaf2ca0e86786acb"), +}, { + Tags: []string{"packfile", "empty-folder"}, + URL: "https://github.com/cpcs499/Final_Pres_P.git", + Head: core.NewHash("70bade703ce556c2c7391a8065c45c943e8b6bc3"), + PackfileHash: core.NewHash("29f304662fd64f102d94722cf5bd8802d9a9472c"), }} func All() Fixtures { @@ -50,7 +69,8 @@ func All() Fixtures { } func Basic() Fixtures { - return ByURL("https://github.com/git-fixtures/basic") + return ByURL("https://github.com/git-fixtures/basic.git"). + Exclude("single-branch") } func ByURL(url string) Fixtures { @@ -80,7 +100,7 @@ func (f *Fixture) Is(tag string) bool { return false } -func (f *Fixture) Packfile() io.ReadSeeker { +func (f *Fixture) Packfile() *os.File { fn := filepath.Join(RootFolder, DataFolder, fmt.Sprintf("pack-%s.pack", f.PackfileHash)) file, err := os.Open(fn) if err != nil { @@ -90,7 +110,7 @@ func (f *Fixture) Packfile() io.ReadSeeker { return file } -func (f *Fixture) Idx() io.ReadSeeker { +func (f *Fixture) Idx() *os.File { fn := filepath.Join(RootFolder, DataFolder, fmt.Sprintf("pack-%s.idx", f.PackfileHash)) file, err := os.Open(fn) if err != nil { @@ -144,3 +164,30 @@ func (g Fixtures) ByURL(url string) Fixtures { return r } + +func (g Fixtures) Exclude(tag string) Fixtures { + r := make(Fixtures, 0) + for _, f := range g { + if !f.Is(tag) { + r = append(r, f) + } + } + + return r +} + +type Suite struct{} + +func (s *Suite) SetUpSuite(c *check.C) { + RootFolder = filepath.Join( + build.Default.GOPATH, + "src", "gopkg.in/src-d/go-git.v4", "fixtures", + ) +} + +func (s *Suite) TearDownSuite(c *check.C) { + for _, f := range folders { + err := os.RemoveAll(f) + c.Assert(err, check.IsNil) + } +} diff --git a/formats/idxfile/decoder_test.go b/formats/idxfile/decoder_test.go index cd90465..8ce2bc7 100644 --- a/formats/idxfile/decoder_test.go +++ b/formats/idxfile/decoder_test.go @@ -13,7 +13,9 @@ import ( func Test(t *testing.T) { TestingT(t) } -type IdxfileSuite struct{} +type IdxfileSuite struct { + fixtures.Suite +} var _ = Suite(&IdxfileSuite{}) @@ -35,7 +37,7 @@ func (s *IdxfileSuite) TestDecode(c *C) { } func (s *IdxfileSuite) TestDecodeCRCs(c *C) { - f := fixtures.Basic().ByTag("ofs-delta") + f := fixtures.Basic().ByTag("ofs-delta").One() scanner := packfile.NewScanner(f.Packfile()) storage := memory.NewStorage() diff --git a/formats/idxfile/encoder_test.go b/formats/idxfile/encoder_test.go index 380b8e8..d9d83eb 100644 --- a/formats/idxfile/encoder_test.go +++ b/formats/idxfile/encoder_test.go @@ -9,10 +9,6 @@ import ( "gopkg.in/src-d/go-git.v4/fixtures" ) -func (s *IdxfileSuite) SetUpSuite(c *C) { - fixtures.RootFolder = "../../fixtures" -} - func (s *IdxfileSuite) TestEncode(c *C) { expected := &Idxfile{} expected.Add(core.NewHash("4bfc730165c370df4a012afbb45ba3f9c332c0d4"), 82, 82) diff --git a/formats/packfile/decoder_test.go b/formats/packfile/decoder_test.go index d85f3bf..9fe6142 100644 --- a/formats/packfile/decoder_test.go +++ b/formats/packfile/decoder_test.go @@ -14,14 +14,12 @@ import ( func Test(t *testing.T) { TestingT(t) } -type ReaderSuite struct{} +type ReaderSuite struct { + fixtures.Suite +} var _ = Suite(&ReaderSuite{}) -func (s *ReaderSuite) SetUpSuite(c *C) { - fixtures.RootFolder = "../../fixtures" -} - func (s *ReaderSuite) TestDecode(c *C) { fixtures.Basic().Test(c, func(f *fixtures.Fixture) { scanner := NewScanner(f.Packfile()) @@ -88,24 +86,23 @@ func (s *ReaderSuite) TestDecodeCRCs(c *C) { } func (s *ReaderSuite) TestReadObjectAt(c *C) { - fixtures.Basic().Test(c, func(f *fixtures.Fixture) { - scanner := NewScanner(f.Packfile()) - storage := memory.NewStorage() + f := fixtures.Basic().One() + scanner := NewScanner(f.Packfile()) + storage := memory.NewStorage() - d := NewDecoder(scanner, storage.ObjectStorage()) + d := NewDecoder(scanner, storage.ObjectStorage()) - // when the packfile is ref-delta based, the offsets are required - if f.Is("ref-delta") { - offsets := getOffsetsFromIdx(f.Idx()) - d.SetOffsets(offsets) - } + // when the packfile is ref-delta based, the offsets are required + if f.Is("ref-delta") { + offsets := getOffsetsFromIdx(f.Idx()) + d.SetOffsets(offsets) + } - // the objects at reference 186, is a delta, so should be recall, - // without being read before. - obj, err := d.ReadObjectAt(186) - c.Assert(err, IsNil) - c.Assert(obj.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") - }) + // the objects at reference 186, is a delta, so should be recall, + // without being read before. + obj, err := d.ReadObjectAt(186) + c.Assert(err, IsNil) + c.Assert(obj.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5") } func AssertObjects(c *C, s *memory.Storage, expects []string) { diff --git a/formats/packfile/scanner_test.go b/formats/packfile/scanner_test.go index 6161fdb..d9fe13c 100644 --- a/formats/packfile/scanner_test.go +++ b/formats/packfile/scanner_test.go @@ -8,14 +8,12 @@ import ( "gopkg.in/src-d/go-git.v4/fixtures" ) -type ScannerSuite struct{} +type ScannerSuite struct { + fixtures.Suite +} var _ = Suite(&ScannerSuite{}) -func (s *ScannerSuite) SetUpSuite(c *C) { - fixtures.RootFolder = "../../fixtures" -} - func (s *ScannerSuite) TestHeader(c *C) { r := fixtures.Basic().One().Packfile() p := NewScanner(r) diff --git a/objects_test.go b/objects_test.go index da9dced..d28ff21 100644 --- a/objects_test.go +++ b/objects_test.go @@ -9,31 +9,19 @@ import ( . "gopkg.in/check.v1" ) -var fixtures = []packedFixture{ +var fixturesURL = []packedFixture{ {"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"}, } type ObjectsSuite struct { BaseSuite - r *Repository - repos map[string]*Repository } var _ = Suite(&ObjectsSuite{}) -func (s *ObjectsSuite) SetUpSuite(c *C) { - s.BaseSuite.SetUpSuite(c) - - s.r = NewMemoryRepository() - err := s.r.Clone(&CloneOptions{URL: RepositoryFixture}) - c.Assert(err, IsNil) - - s.repos = unpackFixtures(c, tagFixtures) -} - func (s *ObjectsSuite) TestNewCommit(c *C) { hash := core.NewHash("a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69") - commit, err := s.r.Commit(hash) + commit, err := s.Repository.Commit(hash) c.Assert(err, IsNil) c.Assert(commit.Hash, Equals, commit.ID()) @@ -61,7 +49,7 @@ func (s *ObjectsSuite) TestNewCommit(c *C) { func (s *ObjectsSuite) TestParseTree(c *C) { hash := core.NewHash("a8d315b2b1c615d43042c3a62402b8a54288cf5c") - tree, err := s.r.Tree(hash) + tree, err := s.Repository.Tree(hash) c.Assert(err, IsNil) c.Assert(tree.Entries, HasLen, 8) diff --git a/references_test.go b/references_test.go index bb7a1cf..a119a7f 100644 --- a/references_test.go +++ b/references_test.go @@ -3,36 +3,18 @@ package git import ( "bytes" "fmt" - "os" "gopkg.in/src-d/go-git.v4/core" - "gopkg.in/src-d/go-git.v4/formats/packfile" . "gopkg.in/check.v1" ) type ReferencesSuite struct { - repos map[string]*Repository + BaseSuite } var _ = Suite(&ReferencesSuite{}) -// create the repositories of the fixtures -func (s *ReferencesSuite) SetUpSuite(c *C) { - s.repos = make(map[string]*Repository, 0) - for _, fix := range fixtureRepos { - s.repos[fix.url] = NewMemoryRepository() - - f, err := os.Open(fix.packfile) - defer f.Close() - c.Assert(err, IsNil) - r := packfile.NewScanner(f) - d := packfile.NewDecoder(r, s.repos[fix.url].s.ObjectStorage()) - _, err = d.Decode() - c.Assert(err, IsNil) - } -} - var referencesTests = [...]struct { // input data to revlist repo string @@ -42,28 +24,28 @@ var referencesTests = [...]struct { revs []string }{ // Tyba git-fixture - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "binary.jpg", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "binary.jpg", []string{ "35e85108805c84807bc66a02d91535e1e24b38b9", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "CHANGELOG", []string{ "b8e471f58bcbca63b07bda20e428190409c2db47", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "go/example.go", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "go/example.go", []string{ "918c48b83bd081e863dbe1b80f8998f058cd8294", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/long.json", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/long.json", []string{ "af2d6a6954d532f8ffb47615169c8fdf9d383a1a", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/short.json", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "json/short.json", []string{ "af2d6a6954d532f8ffb47615169c8fdf9d383a1a", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "LICENSE", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "LICENSE", []string{ "b029517f6300c2da0f4b651b8642506cd6aaf45d", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "php/crappy.php", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "php/crappy.php", []string{ "918c48b83bd081e863dbe1b80f8998f058cd8294", }}, - {"https://github.com/tyba/git-fixture.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "vendor/foo.go", []string{ + {"https://github.com/git-fixtures/basic.git", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", "vendor/foo.go", []string{ "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", }}, {"https://github.com/jamesob/desk.git", "d4edaf0e8101fcea437ebd982d899fe2cc0f9f7b", "LICENSE", []string{ @@ -305,7 +287,7 @@ var referencesTests = [...]struct { func (s *ReferencesSuite) TestRevList(c *C) { for _, t := range referencesTests { - repo, ok := s.repos[t.repo] + repo, ok := s.Repositories[t.repo] c.Assert(ok, Equals, true) commit, err := repo.Commit(core.NewHash(t.commit)) @@ -371,7 +353,7 @@ func (s *ReferencesSuite) TestEquivalent(c *C) { // returns the commits from a slice of hashes func (s *ReferencesSuite) commits(cc *C, repo string, hs ...string) []*Commit { - r, ok := s.repos[repo] + r, ok := s.Repositories[repo] cc.Assert(ok, Equals, true) result := make([]*Commit, 0, len(hs)) for _, h := range hs { diff --git a/repository.go b/repository.go index cc76107..11b7fae 100644 --- a/repository.go +++ b/repository.go @@ -226,16 +226,12 @@ func (r *Repository) Pull(o *PullOptions) error { // Commit return the commit with the given hash func (r *Repository) Commit(h core.Hash) (*Commit, error) { - obj, err := r.s.ObjectStorage().Get(core.CommitObject, h) + commit, err := r.Object(core.CommitObject, h) if err != nil { - if err == core.ErrObjectNotFound { - return nil, ErrObjectNotFound - } return nil, err } - commit := &Commit{r: r} - return commit, commit.Decode(obj) + return commit.(*Commit), nil } // Commits decode the objects into commits @@ -250,44 +246,32 @@ func (r *Repository) Commits() (*CommitIter, error) { // Tree return the tree with the given hash func (r *Repository) Tree(h core.Hash) (*Tree, error) { - obj, err := r.s.ObjectStorage().Get(core.TreeObject, h) + tree, err := r.Object(core.TreeObject, h) if err != nil { - if err == core.ErrObjectNotFound { - return nil, ErrObjectNotFound - } return nil, err } - tree := &Tree{r: r} - return tree, tree.Decode(obj) + return tree.(*Tree), nil } // Blob returns the blob with the given hash func (r *Repository) Blob(h core.Hash) (*Blob, error) { - obj, err := r.s.ObjectStorage().Get(core.BlobObject, h) + blob, err := r.Object(core.BlobObject, h) if err != nil { - if err == core.ErrObjectNotFound { - return nil, ErrObjectNotFound - } return nil, err } - blob := &Blob{} - return blob, blob.Decode(obj) + return blob.(*Blob), nil } // Tag returns a tag with the given hash. func (r *Repository) Tag(h core.Hash) (*Tag, error) { - obj, err := r.s.ObjectStorage().Get(core.TagObject, h) + tag, err := r.Object(core.TagObject, h) if err != nil { - if err == core.ErrObjectNotFound { - return nil, ErrObjectNotFound - } return nil, err } - t := &Tag{r: r} - return t, t.Decode(obj) + return tag.(*Tag), nil } // Tags returns a TagIter that can step through all of the annotated tags @@ -302,7 +286,7 @@ func (r *Repository) Tags() (*TagIter, error) { } // Object returns an object with the given hash. -func (r *Repository) Object(h core.Hash, t core.ObjectType) (Object, error) { +func (r *Repository) Object(t core.ObjectType, h core.Hash) (Object, error) { obj, err := r.s.ObjectStorage().Get(t, h) if err != nil { if err == core.ErrObjectNotFound { diff --git a/repository_test.go b/repository_test.go index dd4539c..4567597 100644 --- a/repository_test.go +++ b/repository_test.go @@ -1,12 +1,8 @@ package git import ( - "fmt" - "os" - "gopkg.in/src-d/go-git.v4/core" - "github.com/alcortesm/tgz" . "gopkg.in/check.v1" ) @@ -35,31 +31,6 @@ type RepositorySuite struct { var _ = Suite(&RepositorySuite{}) -func (s *RepositorySuite) SetUpSuite(c *C) { - s.repos = unpackFixtures(c, tagFixtures, treeWalkerFixtures) - - s.dirFixtures = make(map[string]dirFixture, len(dirFixturesInit)) - for _, fix := range dirFixturesInit { - com := Commentf("fixture name = %s\n", fix.name) - - path, err := tgz.Extract(fix.tgz) - c.Assert(err, IsNil, com) - - s.dirFixtures[fix.name] = dirFixture{ - path: path, - head: core.NewHash(fix.head), - } - } -} - -func (s *RepositorySuite) TearDownSuite(c *C) { - for name, fix := range s.dirFixtures { - err := os.RemoveAll(fix.path) - c.Assert(err, IsNil, Commentf("cannot delete tmp dir for fixture %s: %s\n", - name, fix.path)) - } -} - func (s *RepositorySuite) TestNewRepository(c *C) { r := NewMemoryRepository() c.Assert(r, NotNil) @@ -271,44 +242,40 @@ func (s *RepositorySuite) TestCommits(c *C) { } func (s *RepositorySuite) TestTag(c *C) { - for i, t := range tagTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) - k := 0 - for hashString, exp := range t.tags { - hash := core.NewHash(hashString) - tag, err := r.Tag(hash) - c.Assert(err, IsNil) - testTagExpected(c, tag, hash, exp, fmt.Sprintf("subtest %d, tag %d: ", i, k)) - k++ - } - } + r := NewMemoryRepository() + err := r.Clone(&CloneOptions{URL: "https://github.com/spinnaker/spinnaker.git"}) + c.Assert(err, IsNil) + + hash := core.NewHash("0a3fb06ff80156fb153bcdcc58b5e16c2d27625c") + tag, err := r.Tag(hash) + c.Assert(err, IsNil) + + c.Assert(tag.Hash.IsZero(), Equals, false) + c.Assert(tag.Hash, Equals, hash) + c.Assert(tag.Type(), Equals, core.TagObject) + } func (s *RepositorySuite) TestTags(c *C) { - for i, t := range tagTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) - tagsIter, err := r.Tags() - c.Assert(err, IsNil) - testTagIter(c, tagsIter, t.tags, fmt.Sprintf("subtest %d, ", i)) - } -} + r := NewMemoryRepository() + err := r.Clone(&CloneOptions{URL: "https://github.com/spinnaker/spinnaker.git"}) + c.Assert(err, IsNil) -func (s *RepositorySuite) TestObject(c *C) { - for i, t := range treeWalkerTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) - for k := 0; k < len(t.objs); k++ { - com := fmt.Sprintf("subtest %d, tag %d", i, k) - info := t.objs[k] - hash := core.NewHash(info.Hash) - obj, err := r.Object(hash, core.AnyObject) - c.Assert(err, IsNil, Commentf(com)) - c.Assert(obj.Type(), Equals, info.Kind, Commentf(com)) - c.Assert(obj.ID(), Equals, hash, Commentf(com)) + count := 0 + tags, err := r.Tags() + c.Assert(err, IsNil) + for { + tag, err := tags.Next() + if err != nil { + break } + + count++ + c.Assert(tag.Hash.IsZero(), Equals, false) + c.Assert(tag.Type(), Equals, core.TagObject) } + + c.Assert(count, Equals, 11) } func (s *RepositorySuite) TestCommitIterClosePanic(c *C) { diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go index 955e5a6..ca2b5b4 100644 --- a/storage/filesystem/internal/dotgit/dotgit_test.go +++ b/storage/filesystem/internal/dotgit/dotgit_test.go @@ -20,24 +20,13 @@ import ( func Test(t *testing.T) { TestingT(t) } type SuiteDotGit struct { - fixtures map[string]fs.Filesystem + fixtures.Suite } var _ = Suite(&SuiteDotGit{}) -func (s *SuiteDotGit) SetUpSuite(c *C) { - fixtures.RootFolder = "../../../../fixtures" -} - -func (s *SuiteDotGit) TearDownSuite(c *C) { - for _, f := range s.fixtures { - err := os.RemoveAll(f.Base()) - c.Assert(err, IsNil) - } -} - func (s *SuiteDotGit) TestRefsFromPackedRefs(c *C) { - fs := fixtures.Basic().ByTag(".git").DotGit() + fs := fixtures.Basic().ByTag(".git").One().DotGit() dir := New(fs) refs, err := dir.Refs() @@ -49,7 +38,7 @@ func (s *SuiteDotGit) TestRefsFromPackedRefs(c *C) { } func (s *SuiteDotGit) TestRefsFromReferenceFile(c *C) { - fs := fixtures.Basic().ByTag(".git").DotGit() + fs := fixtures.Basic().ByTag(".git").One().DotGit() dir := New(fs) refs, err := dir.Refs() @@ -63,7 +52,7 @@ func (s *SuiteDotGit) TestRefsFromReferenceFile(c *C) { } func (s *SuiteDotGit) TestRefsFromHEADFile(c *C) { - fs := fixtures.Basic().ByTag(".git").DotGit() + fs := fixtures.Basic().ByTag(".git").One().DotGit() dir := New(fs) refs, err := dir.Refs() @@ -76,7 +65,7 @@ func (s *SuiteDotGit) TestRefsFromHEADFile(c *C) { } func (s *SuiteDotGit) TestConfig(c *C) { - fs := fixtures.Basic().ByTag(".git").DotGit() + fs := fixtures.Basic().ByTag(".git").One().DotGit() dir := New(fs) file, err := dir.Config() @@ -95,15 +84,8 @@ func findReference(refs []*core.Reference, name string) *core.Reference { return nil } -func (s *SuiteDotGit) newFixtureDir(c *C, fixName string) *DotGit { - f, ok := s.fixtures[fixName] - c.Assert(ok, Equals, true) - - return New(f) -} - func (s *SuiteDotGit) TestObjectsPack(c *C) { - f := fixtures.Basic().ByTag(".git") + f := fixtures.Basic().ByTag(".git").One() fs := f.DotGit() dir := New(fs) @@ -114,7 +96,7 @@ func (s *SuiteDotGit) TestObjectsPack(c *C) { } func (s *SuiteDotGit) TestObjectPack(c *C) { - f := fixtures.Basic().ByTag(".git") + f := fixtures.Basic().ByTag(".git").One() fs := f.DotGit() dir := New(fs) @@ -124,7 +106,7 @@ func (s *SuiteDotGit) TestObjectPack(c *C) { } func (s *SuiteDotGit) TestObjectPackIdx(c *C) { - f := fixtures.Basic().ByTag(".git") + f := fixtures.Basic().ByTag(".git").One() fs := f.DotGit() dir := New(fs) @@ -134,7 +116,7 @@ func (s *SuiteDotGit) TestObjectPackIdx(c *C) { } func (s *SuiteDotGit) TestObjectPackNotFound(c *C) { - fs := fixtures.Basic().ByTag(".git").DotGit() + fs := fixtures.Basic().ByTag(".git").One().DotGit() dir := New(fs) pack, err := dir.ObjectPack(core.ZeroHash) @@ -146,7 +128,7 @@ func (s *SuiteDotGit) TestObjectPackNotFound(c *C) { } func (s *SuiteDotGit) TestObjects(c *C) { - fs := fixtures.ByTag(".git").ByTag("unpacked").DotGit() + fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit() dir := New(fs) hashes, err := dir.Objects() @@ -158,7 +140,7 @@ func (s *SuiteDotGit) TestObjects(c *C) { } func (s *SuiteDotGit) TestObject(c *C) { - fs := fixtures.ByTag(".git").ByTag("unpacked").DotGit() + fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit() dir := New(fs) hash := core.NewHash("03db8e1fbe133a480f2867aac478fd866686d69e") @@ -171,7 +153,7 @@ func (s *SuiteDotGit) TestObject(c *C) { } func (s *SuiteDotGit) TestObjectNotFound(c *C) { - fs := fixtures.ByTag(".git").ByTag("unpacked").DotGit() + fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit() dir := New(fs) hash := core.NewHash("not-found-object") diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go index 07fa646..b1546d5 100644 --- a/storage/filesystem/object_test.go +++ b/storage/filesystem/object_test.go @@ -8,14 +8,12 @@ import ( . "gopkg.in/check.v1" ) -type FsSuite struct{} +type FsSuite struct { + fixtures.Suite +} var _ = Suite(&FsSuite{}) -func (s *FsSuite) SetUpSuite(c *C) { - fixtures.RootFolder = "../../fixtures" -} - func (s *FsSuite) TestGetFromObjectFile(c *C) { fs := fixtures.ByTag(".git").ByTag("unpacked").One().DotGit() o, err := newObjectStorage(dotgit.New(fs)) @@ -169,7 +169,7 @@ func (t *Tag) Blob() (*Blob, error) { // Object returns the object pointed to by the tag. func (t *Tag) Object() (Object, error) { - return t.r.Object(t.Target, t.TargetType) + return t.r.Object(t.TargetType, t.Target) } // String returns the meta information contained in the tag as a formatted diff --git a/tag_test.go b/tag_test.go index ac4763b..5f9ad10 100644 --- a/tag_test.go +++ b/tag_test.go @@ -29,7 +29,8 @@ var tagTests = []struct { }{ // https://api.github.com/repos/spinnaker/spinnaker/git/tags/TAGHASH {"https://github.com/spinnaker/spinnaker.git", map[string]expectedTag{ - "48b655898fa9c72d62e8dd73b022ecbddd6e4cc2": {"a77d88e40e86ae81b3ce1c19d04fd73f473f5644", core.CommitObject, "v0.13.0", "cfieber", "cfieber@netflix.com", "2015-11-20T19:37:31Z", "Release of 0.13.0\n\n- a77d88e40e86ae81b3ce1c19d04fd73f473f5644: Merge pull request #606 from duftler/check-log-dirs\n- a174b873e97fb9a2d551d007c92aa5889c081a99: Always check if log dirs exist before starting services via spinnaker umbrella service. Stop/start spinnaker instead of restart since restart seems not happy about a service that is not already running.\n- 8586b7cd3f70fe63053fd5fa321bc86c6b803622: Merge pull request #603 from ewiseblatt/remove_obsolete_scripts\n- 3525c938ab51af81cff2448c8c784b925af2fd0f: Merge pull request #604 from kenzanlabs/kenzan-master\n- b1b5146a77d363e136336923429134d0759eb9c8: Script to generate ami_table.md and ami_table.json files after the jenkins ami build is complete\n- 1ef157853d770a26e7682e543ac42de485b34f77: Removed obsolete scripts.\n"}, + "48b655898fa9c72d62e8dd73b022ecbddd6e4cc2": { + "a77d88e40e86ae81b3ce1c19d04fd73f473f5644", core.CommitObject, "v0.13.0", "cfieber", "cfieber@netflix.com", "2015-11-20T19:37:31Z", "Release of 0.13.0\n\n- a77d88e40e86ae81b3ce1c19d04fd73f473f5644: Merge pull request #606 from duftler/check-log-dirs\n- a174b873e97fb9a2d551d007c92aa5889c081a99: Always check if log dirs exist before starting services via spinnaker umbrella service. Stop/start spinnaker instead of restart since restart seems not happy about a service that is not already running.\n- 8586b7cd3f70fe63053fd5fa321bc86c6b803622: Merge pull request #603 from ewiseblatt/remove_obsolete_scripts\n- 3525c938ab51af81cff2448c8c784b925af2fd0f: Merge pull request #604 from kenzanlabs/kenzan-master\n- b1b5146a77d363e136336923429134d0759eb9c8: Script to generate ami_table.md and ami_table.json files after the jenkins ami build is complete\n- 1ef157853d770a26e7682e543ac42de485b34f77: Removed obsolete scripts.\n"}, "82562fa518f0a2e2187ea2604b07b67f2e7049ae": {"1ea743cd62e8e60f97f55a434a3f46400b49f606", core.CommitObject, "v0.12.0", "cfieber", "cfieber@netflix.com", "2015-11-19T22:04:22Z", "Release of 0.12.0\n\n- 1ea743cd62e8e60f97f55a434a3f46400b49f606: Merge pull request #599 from ewiseblatt/no_distribution\n- 8fe3f13ad04ee25fde0add4ed19d29acd49a5916: Up GCE source image to trusty-v20151113\n- 855e3b979f1d65fbfbcc68df905dafb9945f3825: Merge pull request #601 from ewiseblatt/no_longer_tar\n- d79f2736da55c123ba638710284e2856041262a5: Removed obsolete tar packaging.\n- 2b1ab713af3789204594a45f265cc93858807e98: Merge pull request #600 from ewiseblatt/remove_bootstrap\n- 52831ed7689ab0f481486f62e81d2b4e9e1c535b: Removed obsolete BootstrapSpinnaker.sh\n- 1b44b5467f78a3f5e1915b6fe78f7d0814c29427: Merge pull request #595 from duftler/sync-settings-file\n- 637ba49300f701cfbd859c1ccf13c4f39a9ba1c8: Sync feature block in settings.js.\n- 4f3c7375fa7c661735a6a69beeeeac1aaa43f7c9: Merge pull request #593 from ewiseblatt/2_run_dev_autoconfigure\n- a74422026841e05debdcc417190428b419a99f39: Merge pull request #564 from mstantoncook/master\n- d73f9cee49a5ad27a42a6e18af7c49a8f28ad8a8: Auto-generate spinnaker-local.yml on run_dev first's run.\n- b260ce026a2505037876b4c21c0985882ff373b7: Merge pull request #591 from ewiseblatt/1_move_transform_yaml\n- bb6325e4e629fc7348a6d0e6842280d5304160ff: Moved yaml transform method.\n- 608976766959bdb1b18eaa53b3ca33ee6782bc3c: Merge pull request #590 from kenzanlabs/master\n- cfdd19354e2a3981484a7cfe4b0d95c9abce9296: Merge pull request #589 from ewiseblatt/readme\n- 8ef83dd443a05e9122681950399edaa58a38d466: Updated run_dev instructions.\n- 769ce2a32e60bf2219ffb5b8467d62f71f1e4877: Merge pull request #1 from skorten/cassandra-thrift-fix\n- b2c7142082d52b09ca20228606c31c7479c0833e: using apt-mark to put a hold on cassandra packages so they will not be get upgraded from 2.1 and break thrift\n- d25148149d6a67989be79cdb7452cdab8d2f1a4b: Merge pull request #586 from ewiseblatt/reconfigure\n- c89dab0d42f1856d157357e9010f8cc6a12f5b1f: Fixes reconfigure_spinnaker.sh to behave properly when not run as root.\n- 8a9804234551d61209f67b3c89f7706f248ae805: Merge pull request #581 from ewiseblatt/03_fix_run_dev\n- b45ffa99a6daaf045043ab0b0d8bcf823f10e157: Merge pull request #580 from ewiseblatt/02_create_dev\n- 827682091dd09c1887e82686e36822695b88bb1e: Merge pull request #579 from ewiseblatt/01_install_dev\n- 4f9cd01b6e533c3b1261660b9cc3302879e5b303: Merge pull request #554 from ewiseblatt/fix_transform\n- d1ff4e13e9e0b500821aa558373878f93487e34b: Refactored install_development.sh to use production install\n- 1c370109898641253617a4d48d77f2c9b0a4ccf5: Merge pull request #584 from dpeterka/master\n- 8d1e069744321ff97cbefeaba593c778105c3aad: Cosmetic changes. Fix ports in login script\n- dd7e66c862209e8b912694a582a09c0db3227f0d: Update InstallSpinnaker.sh\n- 4cce5f988005be72dca910fb53e4b2f5802bf7cf: need to add front50 url to clouddriver in configs\n- 0ae9771322873f03893180d90b0af5e3b30154e9: Merge pull request #583 from dpeterka/master\n- e805183c72f0426fb073728c01901c2fd2db1da6: Reconfigure AWS only on boot\n- f98b6099746b849abfb9d5b1db7e861363747be2: Consistent naming for packages\n- 52edbd4c10193f87f8f9768c92789637bfedb867: Don't prompt, just install packer so it's available for rush.\n- d7a3eedbf9fa133d7c4366afae555a2ed46d4849: Merge pull request #582 from saulshanabrook/patch-1\n- 9944d6cf72b8f82d622d85dad7434472bc8f397d: Fix readme link\n- 6694fb99ca6fbf469798f1fb9386b55ff80f0128: Merge pull request #578 from spinnaker/readme-cleanup\n- 174bdbf9edfb0ca88415dd4a673852d5b22e7036: Remove note about packer.\n- 2b28ea424acc8f2817d3298c143fae68bcad91a7: Fix run_dev\n- 206033f8afb2609982fdc6e929a94a340bc80054: Updated create_google_dev_vm (and run_dev)\n- 811795c8a185e88f5d269195cb68b29c8d0fe170: Update README.adoc\n- 4584fab37e93d66fd1896d07fa3427f8056711bc: Removed redudnant attribute\n"}, "3e349f806a0d02bf658c3544c46a0a7a9ee78673": {"6ea37d18b706aab813532254ce0d412843c68782", core.CommitObject, "v0.11.0", "cfieber", "cfieber@netflix.com", "2015-11-17T22:07:00Z", "Release of 0.11.0\n\n- 6ea37d18b706aab813532254ce0d412843c68782: Merge pull request #571 from dpeterka/changeRepoName\n- fad219f07e362f97eda945790320f1f0552a919c: Merge pull request #574 from duftler/always-install-packer\n- 376599177551c3f04ccc94d71bbb4d037dec0c3f: Don't prompt, just install packer so it's available for rush.\n- 9414750a933037ec4f0bc42af7ad81ec4f360c0a: Merge pull request #572 from erjohnso/master\n- d6e6fe0194447cc280f942d6a2e0521b68ea7796: Point non-devs to getting started user docs\n- e259e024b1c7a221e8329fb942a4992738bc81af: update docker compose to use /opt/spinnaker/config\n- b32b2aecae2cfca4840dd480f8082da206a538da: Merge pull request #566 from ewiseblatt/refactor_install\n- 8eed01ff4f2ef7c9c68ab031b54e0cf84a0b1cc9: Consistent naming for packages\n- 66ee9032d57be4bac236edec0e501aaa0501a57d: Merge pull request #570 from spinnaker/cleanup-instructions\n- 24551a5d486969a2972ee05e87f16444890f9555: Update instructions.\n- d4b48a39aba7d3bd3e8abef2274a95b112d1ae73: Add option to only install dependencies without installing spinnaker services.\n- 5ad50e028c59d67ae5d8160e685947582dc68f36: Merge pull request #569 from analytically/master\n- 9a06d3f20eabb254d0a1e2ff7735ef007ccd595e: Fix Ubuntu version.\n- c0a70a0f5aa494f0ae01c55ba191f2325556489a: change heading to setting up spinnaker for development\n- d6905eab6fec1841c7cf8e4484499f5c8d7d423e: update Readme to point to the getting started guide\n- f5300bb86b22eda66eb4baef6b2a211c85f14690: Merge pull request #560 from ewiseblatt/autogen_packages\n- d3046b5b2f7aafa0832da6806ee8c7dab7d0da9e: Merge pull request #559 from ewiseblatt/remove_obsolete_instructions\n- ca87222cb609773c56d43c960e8f0ade554fc138: Removed obsolete instructions output.\n- bd42370d3fe8d410e78acb96f81cb3d838ad1c21: change url for join slack button\n- 67f0a0f488b3592bb611391150f2e1d0ee037231: Merge pull request #558 from gregturn/convert-to-asciidoc\n- 638f61b3331695f46f1a88095e26dea0f09f176b: Convert README to asciidoctor\n- 09a4ea729b25714b6368959eea5113c99938f7b6: Generate bintray packages if needed.\n- 8731e9edc1619e798a76fedb30b26cf48fa62897: Merge pull request #555 from dpeterka/master\n- bcbbd656c19dbc47ffd5b247927ea99f3949c78a: Add VPC Scripts\n"}, "d081d66c2a76d04ff479a3431dc36e44116fde40": {"e0005f50e22140def60260960b21667f1fdfff80", core.CommitObject, "v0.10.0", "cfieber", "cfieber@netflix.com", "2015-11-16T15:25:36Z", "Release of 0.10.0\n\n- e0005f50e22140def60260960b21667f1fdfff80: Merge pull request #553 from ewiseblatt/rendezvous\n- e1a2b26b784179e6903a7ae967c037c721899eba: Wait for cassandra before starting spinnaker\n- c756e09461d071e98b8660818cf42d90c90f2854: Merge pull request #552 from duftler/google-c2d-tweaks\n- 0777fadf4ca6f458d7071de414f9bd5417911037: Fix incorrect config prop names: s/SPINNAKER_GOOGLE_PROJECT_DEFAULT_REGION/SPINNAKER_GOOGLE_DEFAULT_REGION s/SPINNAKER_GOOGLE_PROJECT_DEFAULT_ZONE/SPINNAKER_GOOGLE_DEFAULT_ZONE Hardcode profile name in generated ~/.aws/credentials to [default]. Restart all of spinnaker after updating cassandra and reconfiguring spinnaker, instead of just restarting clouddriver.\n- d8d031c1ac45801074418c43424a6f2c0dff642c: Merge pull request #551 from kenzanmedia/fixGroup\n- 626d23075f9e92aad19015f2964c95d45f41fa3a: Put in correct block for public image. Delineate cloud provider.\n"}, @@ -45,20 +46,17 @@ var tagTests = []struct { // TODO: Add fixture with tagged blobs } -type SuiteTag struct { +type TagSuite struct { repos map[string]*Repository + BaseSuite } -var _ = Suite(&SuiteTag{}) +var _ = Suite(&TagSuite{}) -func (s *SuiteTag) SetUpSuite(c *C) { - s.repos = unpackFixtures(c, tagFixtures) -} - -func (s *SuiteTag) TestCommit(c *C) { +func (s *TagSuite) TestCommit(c *C) { for _, t := range tagTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) + r := s.Clone(t.repo) + k := 0 for hash, exp := range t.tags { if exp.Type != core.CommitObject { @@ -75,10 +73,9 @@ func (s *SuiteTag) TestCommit(c *C) { } } -func (s *SuiteTag) TestTree(c *C) { +func (s *TagSuite) TestTree(c *C) { for _, t := range tagTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) + r := s.Clone(t.repo) k := 0 for hash, exp := range t.tags { if exp.Type != core.TreeObject { @@ -95,15 +92,15 @@ func (s *SuiteTag) TestTree(c *C) { } } -func (s *SuiteTag) TestBlob(c *C) { +func (s *TagSuite) TestBlob(c *C) { for _, t := range tagTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) + r := s.Clone(t.repo) k := 0 for hashString, exp := range t.tags { if exp.Type != core.BlobObject { continue } + fmt.Println(exp) hash := core.NewHash(hashString) tag, err := r.Tag(hash) c.Assert(err, IsNil) @@ -117,10 +114,9 @@ func (s *SuiteTag) TestBlob(c *C) { } } -func (s *SuiteTag) TestObject(c *C) { +func (s *TagSuite) TestObject(c *C) { for _, t := range tagTests { - r, ok := s.repos[t.repo] - c.Assert(ok, Equals, true) + r := s.Clone(t.repo) k := 0 for hashString, exp := range t.tags { if exp.Type != core.BlobObject { @@ -139,7 +135,7 @@ func (s *SuiteTag) TestObject(c *C) { } } -func (s *SuiteTag) TestTagEncodeDecodeIdempotent(c *C) { +func (s *TagSuite) TestTagEncodeDecodeIdempotent(c *C) { ts, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00") c.Assert(err, IsNil) tags := []*Tag{ diff --git a/tree_walker_test.go b/tree_walker_test.go index fe6bcae..973b293 100644 --- a/tree_walker_test.go +++ b/tree_walker_test.go @@ -8,116 +8,49 @@ import ( . "gopkg.in/check.v1" ) -type expectedTreeWalkerEntry struct { - Kind core.ObjectType - Mode string - Name string - Hash string +type TreeWalkerSuite struct { + BaseSuite } -var treeWalkerFixtures = []packedFixture{ - {"https://github.com/alcortesm/binary-relations.git", "formats/packfile/fixtures/alcortesm-binary-relations.pack"}, - {"https://github.com/Tribler/dispersy.git", "formats/packfile/fixtures/tribler-dispersy.pack"}, -} +var _ = Suite(&TreeWalkerSuite{}) -var treeWalkerTests = []struct { - repo string // the repo name as in localRepos - commit string // the commit to search for the file - objs []expectedTreeWalkerEntry // the expected objects in the commit -}{ - // https://api.github.com/repos/alcortesm/binary-relations/git/trees/b373f85fa2594d7dcd9989f4a5858a81647fb8ea - {"https://github.com/alcortesm/binary-relations.git", "b373f85fa2594d7dcd9989f4a5858a81647fb8ea", []expectedTreeWalkerEntry{ - {core.BlobObject, "100644", ".gitignore", "7f41905b4d77ab4a9a2d334fcd0fb5db6e8e2183"}, - {core.BlobObject, "100644", "Makefile", "d441e4e769b53cbd4b1215a1387f8c3108bac97d"}, - {core.BlobObject, "100644", "binary-relations.tex", "cb50b067cc8cd9f639611d41416575c991ad8e97"}, - {core.TreeObject, "040000", "imgs-gen", "b33007b7e83a738576c3f44369fe2f674bb23d5d"}, - {core.TreeObject, "040000", "imgs-gen/simple-graph", "056633542b8ee990d6c89b7a812209dba13d6766"}, - {core.BlobObject, "100644", "imgs-gen/simple-graph/Makefile", "49560402c1707f29c159ad14f369027250fb154a"}, - {core.BlobObject, "100644", "imgs-gen/simple-graph/fig.fig", "2c414eb36f0c2e9a2f9c6382d85e63355752170c"}, - {core.TreeObject, "040000", "src", "ec9d27c4df99caec3a817e9c018812a6c56c1b00"}, - {core.TreeObject, "040000", "src/map-slice", "00cefb8e77f7a8c61b99dd2491ff48a3b0b16679"}, - {core.BlobObject, "100644", "src/map-slice/map-slice.go", "12431e98381dd5097e1a19fe53429c72ef1f328e"}, - {core.TreeObject, "040000", "src/simple-arrays", "9a3781b7fd9d2851e2a4488c035ed9ac905aec79"}, - {core.BlobObject, "100644", "src/simple-arrays/simple-arrays.go", "104fbb4b0520c192f2e207a2dfd39162f6cdabf7"}, - }}, - // https://api.github.com/repos/Tribler/dispersy/git/trees/f5a1fca709f760bf75a7adaa480bf0f0e1a547ee - {"https://github.com/Tribler/dispersy.git", "f5a1fca709f760bf75a7adaa480bf0f0e1a547ee", []expectedTreeWalkerEntry{ - {core.BlobObject, "100644", "__init__.py", "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"}, - {core.BlobObject, "100644", "authentication.py", "ca2fb017dce4506c4144ba81d3cbb70563487718"}, - {core.BlobObject, "100644", "bloomfilter.py", "944e8ccc76779aad923f88f4a73b0d4e8999b6ea"}, - {core.BlobObject, "100644", "bootstrap.py", "379a4400b992310f54ea56a4691760bdea8b1592"}, - {core.BlobObject, "100644", "cache.py", "744d48dce50703e7d4ff14531ab2ab77e6b54685"}, - {core.BlobObject, "100644", "callback.py", "f3a380cbe9eb1c02fb305f2bd2fc0fcfb103892f"}, - {core.BlobObject, "100644", "candidate.py", "87309a51d3681bf6c46b22ce044dad41c97d32d2"}, - {core.BlobObject, "100644", "community.py", "38226ffc2139a2349edaf016747d02b199508d41"}, - {core.BlobObject, "100644", "conversion.py", "4e2fcefba40d99c2a6237768ed0fbb8e2e770c83"}, - {core.BlobObject, "100644", "crypto.py", "8a6bb00df982fa806ce18838673ab1ef3fd52fed"}, - {core.BlobObject, "100644", "database.py", "bb484bfd31a92f7775dbd3acf8740abf00bb3d74"}, - {core.BlobObject, "100644", "debug.py", "3743f20d321f7b2b6d3b47211f93317818c3673e"}, - {core.BlobObject, "100644", "debugcommunity.py", "1598ec5a773cc561430c5bb9b87157ef7d3e1c7c"}, - {core.BlobObject, "100644", "decorator.py", "a1e913e674aec5402cc7b4e9fc0801e8155d2cec"}, - {core.BlobObject, "100644", "destination.py", "d5c02588117d260e728d5c64aba885522ba508c5"}, - {core.BlobObject, "100644", "dispersy.py", "63a08602e2ac8294b20543f0c89c75c740bf6c1c"}, - {core.BlobObject, "100644", "dispersydatabase.py", "76dd222444c308c470efabde7ed511825004b4d3"}, - {core.BlobObject, "100644", "distribution.py", "55a11beca7c09013f5b8ff46baa85b15948c756a"}, - {core.BlobObject, "100644", "dprint.py", "fd6a8608d62bf415a65e78c9e1ca8df97513e598"}, - {core.BlobObject, "100644", "encoding.py", "f29b0ebf65f06a0aa7b2ff1aea364f7889c58d56"}, - {core.BlobObject, "100644", "endpoint.py", "5aa76efd3501de522dbdf2e6374440cf64131423"}, - {core.BlobObject, "100644", "member.py", "c114c73f710b4c291305e353b4aa0106fafabd52"}, - {core.BlobObject, "100644", "message.py", "e55bfe0efa851c4e94264dc745141f7f65b1d239"}, - {core.BlobObject, "100644", "meta.py", "0f62db0fb93326daad6b4925a7d12155a1687f67"}, - {core.BlobObject, "100644", "payload.py", "0aef13194c51dab3624665340b33dd4040516c86"}, - {core.BlobObject, "100644", "requestcache.py", "7772c7d81b4b205970cac1a3cdabc2c2deb48b12"}, - {core.BlobObject, "100644", "resolution.py", "525d6ec81c1fb098d2fe12ae0d5b10a368bfcace"}, - {core.BlobObject, "100644", "script.py", "ef64e12cc1a4c0b3a5d42ff1b33adef202f30da3"}, - {core.BlobObject, "100644", "singleton.py", "34662093edf45bbffa91125c13735e37410a185b"}, - {core.BlobObject, "100644", "timeline.py", "826bb5e1802fb5eaf3144a9a195a994920101880"}, - {core.TreeObject, "040000", "tool", "da97281af01b5b2dad1de6c84c5acb44da60ef7a"}, - {core.BlobObject, "100644", "tool/__init__.py", "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"}, - {core.BlobObject, "100644", "tool/callbackscript.py", "eb9f8184ef08d9e031936e61bfa86fb9b45b965c"}, - {core.BlobObject, "100644", "tool/scenarioscript.py", "245c41af66aab8f0a6fd00259b30a47f4d6c00dd"}, - }}, - {"https://github.com/Tribler/dispersy.git", "9d38ff85ca03adcf68dc14f5b68b8994f15229f4", []expectedTreeWalkerEntry(nil)}, -} - -type SuiteTreeWalker struct { - repos map[string]*Repository -} +func (s *TreeWalkerSuite) TestNext(c *C) { + r := s.Repository + commit, err := r.Commit(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) + c.Assert(err, IsNil) -var _ = Suite(&SuiteTreeWalker{}) + tree, err := commit.Tree() + c.Assert(err, IsNil) -// create the repositories of the fixtures -func (s *SuiteTreeWalker) SetUpSuite(c *C) { - s.repos = unpackFixtures(c, treeWalkerFixtures) -} - -func (s *SuiteTreeWalker) TestNext(c *C) { - for i, t := range treeWalkerTests { - r := s.repos[t.repo] - commit, err := r.Commit(core.NewHash(t.commit)) - c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) - - tree, err := commit.Tree() - c.Assert(err, IsNil) - - walker := NewTreeWalker(r, tree) - for k := 0; k < len(t.objs); k++ { - info := t.objs[k] - c.Assert(err, IsNil) - name, entry, err := walker.Next() - - c.Assert(err, IsNil, Commentf("subtest %d, iter %d, err=%v", i, k, err)) - c.Assert(name, Equals, info.Name, - Commentf("subtest %d, iter %d, name=%v, expected=%s, stack=%v, base=%v", i, k, name, info.Name, walker.stack, walker.base)) - - c.Assert(entry.Hash.String(), Equals, info.Hash, - Commentf("subtest %d, iter %d, entry.Hash=%v, expected=%s", i, k, entry.Hash, info.Hash)) - - c.Assert(entry.Hash.String(), Equals, info.Hash, - Commentf("subtest %d, iter %d, obj.ID()=%v, expected=%s", i, k, entry.Hash.String(), info.Hash)) + walker := NewTreeWalker(r, tree) + for _, e := range treeWalkerExpects { + name, entry, err := walker.Next() + if err == io.EOF { + break } - _, _, err = walker.Next() - c.Assert(err, Equals, io.EOF) + c.Assert(err, IsNil) + c.Assert(name, Equals, e.Path) + c.Assert(entry.Name, Equals, e.Name) + c.Assert(entry.Mode.String(), Equals, e.Mode) + c.Assert(entry.Hash.String(), Equals, e.Hash) } } + +var treeWalkerExpects = []struct { + Path, Mode, Name, Hash string +}{ + {Path: ".gitignore", Mode: "-rw-r--r--", Name: ".gitignore", Hash: "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88"}, + {Path: "CHANGELOG", Mode: "-rw-r--r--", Name: "CHANGELOG", Hash: "d3ff53e0564a9f87d8e84b6e28e5060e517008aa"}, + {Path: "LICENSE", Mode: "-rw-r--r--", Name: "LICENSE", Hash: "c192bd6a24ea1ab01d78686e417c8bdc7c3d197f"}, + {Path: "binary.jpg", Mode: "-rw-r--r--", Name: "binary.jpg", Hash: "d5c0f4ab811897cadf03aec358ae60d21f91c50d"}, + {Path: "go", Mode: "d---------", Name: "go", Hash: "a39771a7651f97faf5c72e08224d857fc35133db"}, + {Path: "go/example.go", Mode: "-rw-r--r--", Name: "example.go", Hash: "880cd14280f4b9b6ed3986d6671f907d7cc2a198"}, + {Path: "json", Mode: "d---------", Name: "json", Hash: "5a877e6a906a2743ad6e45d99c1793642aaf8eda"}, + {Path: "json/long.json", Mode: "-rw-r--r--", Name: "long.json", Hash: "49c6bb89b17060d7b4deacb7b338fcc6ea2352a9"}, + {Path: "json/short.json", Mode: "-rw-r--r--", Name: "short.json", Hash: "c8f1d8c61f9da76f4cb49fd86322b6e685dba956"}, + {Path: "php", Mode: "d---------", Name: "php", Hash: "586af567d0bb5e771e49bdd9434f5e0fb76d25fa"}, + {Path: "php/crappy.php", Mode: "-rw-r--r--", Name: "crappy.php", Hash: "9a48f23120e880dfbe41f7c9b7b708e9ee62a492"}, + {Path: "vendor", Mode: "d---------", Name: "vendor", Hash: "cf4aa3b38974fb7d81f367c0830f7d78d65ab86b"}, + {Path: "vendor/foo.go", Mode: "-rw-r--r--", Name: "foo.go", Hash: "9dea2395f5403188298c1dabe8bdafe562c491e3"}, +} |