-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect number of bytes returned by value decoders
- Loading branch information
1 parent
84240e7
commit ee12c56
Showing
5 changed files
with
100 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package producer | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestDecodeBytesBase64WhenInputIsNil(t *testing.T) { | ||
got, err := decodeBytes(nil, "base64") | ||
if got != nil { | ||
t.Errorf("Expected nil, got %v", got) | ||
} | ||
if err != nil { | ||
t.Errorf("Expected nil, got %v", err) | ||
} | ||
} | ||
|
||
func TestDecodeBytesBase64WhenInputIsInvalid(t *testing.T) { | ||
got, err := decodeBytes([]byte("..this..is..not..base64.."), "base64") | ||
if got != nil { | ||
t.Errorf("Expected nil, got %v", got) | ||
} | ||
if err == nil { | ||
t.Errorf("Expected error, got nil") | ||
} | ||
} | ||
|
||
func TestDecodeBytesBase64WithRegularInput(t *testing.T) { | ||
// length 4 | ||
got, err := decodeBytes([]byte("dGVzdA=="), "base64") | ||
if string(got) != "test" { | ||
t.Errorf("Expected hello, got %v", string(got)) | ||
} | ||
if err != nil { | ||
t.Errorf("Expected nil, got %v", err) | ||
} | ||
// length 5 | ||
got, err = decodeBytes([]byte("aGVsbG8="), "base64") | ||
if string(got) != "hello" { | ||
t.Errorf("Expected hello, got %v", string(got)) | ||
} | ||
if err != nil { | ||
t.Errorf("Expected nil, got %v", err) | ||
} | ||
|
||
// length 6 | ||
got, err = decodeBytes([]byte("aGVsbG8h"), "base64") | ||
if string(got) != "hello!" { | ||
t.Errorf("Expected hello, got %v", string(got)) | ||
} | ||
if err != nil { | ||
t.Errorf("Expected nil, got %v", err) | ||
} | ||
} | ||
|
||
func TestDecodeBytesBase64WithZeroPaddedInput(t *testing.T) { | ||
got, err := decodeBytes([]byte("AAAAAAAD"), "base64") | ||
expected := []byte{0, 0, 0, 0, 0, 3} | ||
if !reflect.DeepEqual(got, expected) { | ||
t.Errorf("Expected hello, got %v", got) | ||
} | ||
if err != nil { | ||
t.Errorf("Expected nil, got %v", err) | ||
} | ||
} |
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,3 @@ | ||
{"key": "1", "value": "AAAAAAAB"} | ||
{"key": "2", "value": "aGVsbG8="} | ||
{"key": "3", "value": "a2Fma2E="} |