-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Danilo Luvizotto
committed
Apr 23, 2018
1 parent
978c3e2
commit b44e6d3
Showing
7 changed files
with
79 additions
and
22 deletions.
There are no files selected for viewing
Binary file not shown.
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,72 @@ | ||
package compression | ||
|
||
import ( | ||
"flag" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/topfreegames/pitaya/helpers" | ||
) | ||
|
||
var update = flag.Bool("update", false, "update .golden files") | ||
|
||
func TestCompressionDeflate(t *testing.T) { | ||
ins := []struct { | ||
name string | ||
data string | ||
}{ | ||
{"compression_deflate_test_1", "test"}, | ||
{"compression_deflate_test_2", "{a:1,b:2}"}, | ||
{"compression_deflate_test_3", "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit"}, | ||
} | ||
|
||
for _, in := range ins { | ||
t.Run(in.name, func(t *testing.T) { | ||
b, err := DeflateData([]byte(in.data)) | ||
require.NoError(t, err) | ||
gp := filepath.Join("fixtures", in.name+".golden") | ||
if *update { | ||
t.Log("updating golden file") | ||
helpers.WriteFile(t, gp, b) | ||
} | ||
expected := helpers.ReadFile(t, gp) | ||
|
||
assert.Equal(t, expected, b) | ||
}) | ||
} | ||
} | ||
|
||
func TestCompressionInflate(t *testing.T) { | ||
ins := []struct { | ||
name string | ||
data string | ||
}{ | ||
{"compression_deflate_test_1", "test"}, | ||
{"compression_deflate_test_2", "{a:1,b:2}"}, | ||
{"compression_deflate_test_3", "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit"}, | ||
} | ||
|
||
for _, in := range ins { | ||
t.Run(in.name, func(t *testing.T) { | ||
inputFile := filepath.Join("fixtures", in.name+".golden") | ||
input := helpers.ReadFile(t, inputFile) | ||
|
||
result, err := InflateData(input) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, string(result), in.data) | ||
}) | ||
} | ||
} | ||
|
||
func TestCompressionInflateIncorrectData(t *testing.T) { | ||
t.Run("compression_deflate_incorrect_data", func(t *testing.T) { | ||
input := "arbitrary data" | ||
|
||
result, err := InflateData([]byte(input)) | ||
require.Error(t, err) | ||
assert.Nil(t, result) | ||
}) | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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