-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
archiver creates a single empty file
- Loading branch information
0 parents
commit 04a476f
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/pzip | ||
|
||
go 1.20 | ||
|
||
require github.com/alecthomas/assert/v2 v2.3.0 | ||
|
||
require ( | ||
github.com/alecthomas/repr v0.2.0 // indirect | ||
github.com/hexops/gotextdiff v1.0.3 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0= | ||
github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= | ||
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= | ||
github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= | ||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= | ||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"io" | ||
"os" | ||
) | ||
|
||
func Archive(archive *os.File, r io.Reader) { | ||
writer := zip.NewWriter(archive) | ||
defer writer.Close() | ||
|
||
writer.Create("hello.txt") | ||
} | ||
|
||
func main() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
) | ||
|
||
func TestArchive(t *testing.T) { | ||
t.Run("archives a single empty file", func(t *testing.T) { | ||
file := strings.NewReader("") | ||
archive, cleanup := createTempArchive(t, "testdata/archive.zip") | ||
defer cleanup() | ||
|
||
Archive(archive, file) | ||
|
||
archiveReader, err := zip.OpenReader(archive.Name()) | ||
assert.NoError(t, err) | ||
defer archiveReader.Close() | ||
|
||
assert.Equal(t, 1, len(archiveReader.File)) | ||
}) | ||
|
||
} | ||
|
||
func createTempArchive(t testing.TB, name string) (*os.File, func()) { | ||
t.Helper() | ||
|
||
archive, err := os.Create(name) | ||
assert.NoError(t, err, fmt.Sprintf("could not create archive %s: %v", name, err)) | ||
|
||
cleanup := func() { | ||
archive.Close() | ||
os.RemoveAll(archive.Name()) | ||
} | ||
|
||
return archive, cleanup | ||
} |