Skip to content

Commit

Permalink
Testing for fileMode persistence & consolidation of if statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
jabgibson committed Jun 6, 2016
1 parent 16d34f3 commit e1b068b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ func writeNewFile(fpath string, in io.Reader, fm os.FileMode) error {
defer out.Close()

err = out.Chmod(fm)
if err != nil {
if runtime.GOOS != "windows" {
return fmt.Errorf("%s: changing file mode: %v", fpath, err)
}
if err != nil && runtime.GOOS != "windows" {
return fmt.Errorf("%s: changing file mode: %v", fpath, err)
}

_, err = io.Copy(out, in)
Expand Down
12 changes: 12 additions & 0 deletions zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,29 @@ func symmetricTest(t *testing.T, ext string, cf CompressFunc, dcf DecompressFunc
return nil
}

expectedFileInfo, err := os.Stat(origPath)
if err != nil {
t.Fatalf("%s: Error obtaining original file info: %v", fpath, err)
}
expected, err := ioutil.ReadFile(origPath)
if err != nil {
t.Fatalf("%s: Couldn't open original file (%s) from disk: %v",
fpath, origPath, err)
}

actualFileInfo, err := os.Stat(fpath)
if err != nil {
t.Fatalf("%s: Error obtaining actual file info: %v", fpath, err)
}
actual, err := ioutil.ReadFile(fpath)
if err != nil {
t.Fatalf("%s: Couldn't open new file from disk: %v", fpath, err)
}

if actualFileInfo.Mode() != expectedFileInfo.Mode() {
t.Fatalf("%s: File mode differed between on disk and compressed",
expectedFileInfo.Mode().String()+" : "+actualFileInfo.Mode().String())
}
if !bytes.Equal(expected, actual) {
t.Fatalf("%s: File contents differed between on disk and compressed", origPath)
}
Expand Down

0 comments on commit e1b068b

Please sign in to comment.