-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add compression test and fix linting/tests
- Loading branch information
Showing
7 changed files
with
82 additions
and
20 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
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
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
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
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,57 @@ | ||
package compress | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCompress(t *testing.T) { | ||
ctx := context.Background() | ||
fsys := afero.NewMemMapFs() | ||
|
||
compressor, err := New(&CompressorConfig{Method: "targz", FS: fsys}) | ||
require.NoError(t, err) | ||
|
||
// Prepare input for compression | ||
input, err := fsys.Create("compress") | ||
require.NoError(t, err) | ||
|
||
err = afero.WriteFile(fsys, input.Name(), []byte("This is the content of the file"), 0600) | ||
require.NoError(t, err) | ||
|
||
// Compress files | ||
output, err := fsys.Create("compress.targz") | ||
require.NoError(t, err) | ||
|
||
files, err := compressor.BuildFilesForCompression("compress", input.Name()) | ||
require.NoError(t, err) | ||
|
||
err = compressor.Compress(ctx, output, files) | ||
require.NoError(t, err) | ||
|
||
// Prepare input for decompression | ||
inputDecompressed, err := fsys.Open("compress.targz") | ||
require.NoError(t, err) | ||
|
||
err = fsys.Remove("compress") | ||
require.NoError(t, err) | ||
|
||
// Decompress files | ||
err = compressor.Decompress(ctx, inputDecompressed, "./") | ||
require.NoError(t, err) | ||
|
||
outputDecompressed, err := fsys.Open("compress") | ||
require.NoError(t, err) | ||
|
||
cleartext, err := afero.ReadFile(fsys, outputDecompressed.Name()) | ||
require.NoError(t, err) | ||
|
||
println("cleartext: ") | ||
println(string(cleartext)) | ||
|
||
require.Equal(t, []byte("This is the content of the file"), (cleartext)) | ||
|
||
} |
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
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