-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add tests for utils * chore:delete unused code * fix: ipv6 validation issue
- Loading branch information
1 parent
54c0221
commit bc06867
Showing
5 changed files
with
53 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHexDecoding(t *testing.T) { | ||
const s = "0x48656c6c6f20476f7068657221" | ||
decodedString, err := DecodeHexString(s) | ||
require.NoError(t, err) | ||
require.Equal(t, decodedString, []byte("Hello Gopher!")) | ||
|
||
const s1 = "48656c6c6f20476f7068657221" | ||
_, err = DecodeHexString(s1) | ||
require.NoError(t, err) | ||
require.Equal(t, decodedString, []byte("Hello Gopher!")) | ||
|
||
const s2 = "jk" | ||
_, err = DecodeHexString(s2) | ||
require.Error(t, err) | ||
|
||
const s3 = "48656c6c6f20476f706865722" | ||
_, err = DecodeHexString(s3) | ||
require.Error(t, 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
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,20 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIPValidation(t *testing.T) { | ||
require.Equal(t, IsIPv4("127.0.0.1"), true) | ||
require.Equal(t, IsIPv4("abcd"), false) | ||
require.Equal(t, IsIPv4("::1"), false) | ||
require.Equal(t, IsIPv4("1000.40.210.253"), false) | ||
|
||
require.Equal(t, IsIPv6("::1"), true) | ||
require.Equal(t, IsIPv6("fe80::6c4a:6aff:fecf:8097"), true) | ||
require.Equal(t, IsIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334:3445"), false) | ||
require.Equal(t, IsIPv6("127.0.0.1"), false) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.