Skip to content

Commit

Permalink
fix tests build (#35)
Browse files Browse the repository at this point in the history
* fix tests build

Code was broken after merging #30 and #31 together.

Signed-off-by: Santiago M. Mola <[email protected]>

* fix paths on Windows, ensure closing

Signed-off-by: Santiago M. Mola <[email protected]>

* travis: update go versions

Signed-off-by: Santiago M. Mola <[email protected]>
  • Loading branch information
smola authored Sep 28, 2018
1 parent 1554de3 commit a31824b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ language: go
go_import_path: gopkg.in/src-d/go-siva.v1

go:
- 1.9.x
- 1.10.x
- tip

matrix:
fast_finish: true
allow_failures:
- go: tip
- 1.11.x

install:
- make dependencies
Expand Down
8 changes: 6 additions & 2 deletions cmd/siva/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ func (c *CmdPack) do() error {
return err
}

defer c.close()
return c.pack()
if err := c.pack(); err != nil {
_ = c.close()
return err
}

return c.close()
}

func (c *CmdPack) validate() error {
Expand Down
12 changes: 7 additions & 5 deletions cmd/siva/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func (s *PackSuite) SetUpTest(c *C) {
}

func (s *PackSuite) TearDownTest(c *C) {
err := os.RemoveAll(s.folder)
err := os.Chdir(s.cwd)
c.Assert(err, IsNil)
err = os.Chdir(s.cwd)
err = os.RemoveAll(s.folder)
c.Assert(err, IsNil)
}

Expand All @@ -73,7 +73,7 @@ func (s *PackSuite) TestBasic(c *C) {
c.Assert(err, IsNil)
size := 249
for _, file := range s.files {
size += len(cleanPath(file))
size += len(siva.ToSafePath(file))
}
c.Assert(int(fi.Size()), Equals, size)

Expand All @@ -100,7 +100,7 @@ func (s *PackSuite) TestDir(c *C) {
c.Assert(err, IsNil)
size := 249
for _, file := range s.files {
size += len(cleanPath(file))
size += len(siva.ToSafePath(file))
}
c.Assert(int(fi.Size()), Equals, size)

Expand Down Expand Up @@ -133,7 +133,7 @@ func (s *PackSuite) TestAppend(c *C) {

size := 277
for _, file := range s.files {
size += len(cleanPath(file))
size += len(siva.ToSafePath(file))
}
c.Assert(int(fi.Size()), Equals, size)

Expand Down Expand Up @@ -174,6 +174,8 @@ func (s *PackSuite) TestCleanPaths(c *C) {
entry := i.Find("gopher.txt")
c.Assert(entry, NotNil)
c.Assert(entry.Name, Equals, "gopher.txt")

c.Assert(f.Close(), IsNil)
}

type fileFixture struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/siva/siva.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (c *cmd) buildWriter(append bool) (err error) {

c.fi, err = c.f.Stat()
if err != nil {
_ = c.f.Close()
return err
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/siva/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *UnpackSuite) TearDownTest(c *C) {
func (s *UnpackSuite) TestBasic(c *C) {
cmd := &CmdUnpack{}
cmd.Output.Path = filepath.Join(s.folder, "files")
cmd.Args.File = "../../fixtures/perms.siva"
cmd.Args.File = filepath.Join("..", "..", "fixtures", "perms.siva")
cmd.Overwrite = true

err := cmd.Execute(nil)
Expand Down Expand Up @@ -57,7 +57,7 @@ func (s *UnpackSuite) TestBasic(c *C) {
func (s *UnpackSuite) TestIgnorePerms(c *C) {
cmd := &CmdUnpack{}
cmd.Output.Path = filepath.Join(s.folder, "files")
cmd.Args.File = "../../fixtures/perms.siva"
cmd.Args.File = filepath.Join("..", "..", "fixtures", "perms.siva")
cmd.IgnorePerms = true

err := cmd.Execute(nil)
Expand All @@ -75,7 +75,7 @@ func (s *UnpackSuite) TestIgnorePerms(c *C) {
func (s *UnpackSuite) TestMatch(c *C) {
cmd := &CmdUnpack{}
cmd.Output.Path = filepath.Join(s.folder, "files")
cmd.Args.File = "../../fixtures/basic.siva"
cmd.Args.File = filepath.Join("..", "..", "fixtures", "basic.siva")
cmd.Match = "gopher(.*)"

err := cmd.Execute(nil)
Expand All @@ -90,7 +90,7 @@ func (s *UnpackSuite) TestMatch(c *C) {
func (s *UnpackSuite) TestOverwrite(c *C) {
cmd := &CmdUnpack{}
cmd.Output.Path = filepath.Join(s.folder, "files")
cmd.Args.File = "../../fixtures/duplicate.siva"
cmd.Args.File = filepath.Join("..", "..", "fixtures", "duplicate.siva")
cmd.Overwrite = true

err := cmd.Execute(nil)
Expand All @@ -104,7 +104,7 @@ func (s *UnpackSuite) TestOverwrite(c *C) {
func (s *UnpackSuite) TestZipSlip(c *C) {
cmd := &CmdUnpack{}
cmd.Output.Path = filepath.Join(s.folder, "files/inside")
cmd.Args.File = "../../fixtures/zipslip.siva"
cmd.Args.File = filepath.Join("..", "..", "fixtures", "zipslip.siva")

err := cmd.Execute(nil)
c.Assert(err, NotNil)
Expand Down

0 comments on commit a31824b

Please sign in to comment.