Skip to content

Commit

Permalink
ensure pointer value
Browse files Browse the repository at this point in the history
  • Loading branch information
RangelReale committed Jul 8, 2023
1 parent ca3e7d6 commit f485302
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ func TestDecodeNoContext(t *testing.T) {

func TestDecodePointerField(t *testing.T) {
type SData struct {
Val string `instruct:"header"`
IntVal *int32 `instruct:"header"`
Val string `instruct:"header"`
IntVal *int32 `instruct:"header"`
IntVal2 **int64 `instruct:"header"`
}

type DataType struct {
Expand All @@ -163,6 +164,7 @@ func TestDecodePointerField(t *testing.T) {
r := httptest.NewRequest(http.MethodPost, "/", nil)
r.Header.Set("val", "x1")
r.Header.Set("intval", "92")
r.Header.Set("intval2", "799")

var data DataType

Expand All @@ -177,10 +179,13 @@ func TestDecodePointerField(t *testing.T) {
require.Equal(t, int32(92), *data.IntVal)
require.Equal(t, "x1", data.S.Val)
require.Equal(t, int32(92), *data.S.IntVal)
require.Equal(t, int64(799), **data.S.IntVal2)
require.Equal(t, "x1", (*data.S2).Val)
require.Equal(t, int32(92), *(*data.S2).IntVal)
require.Equal(t, int64(799), **(*data.S2).IntVal2)
require.Equal(t, "x1", (**data.S3).Val)
require.Equal(t, int32(92), *(**data.S3).IntVal)
require.Equal(t, int64(799), **(**data.S3).IntVal2)
}

func TestDecodePointerPointerField(t *testing.T) {
Expand Down

0 comments on commit f485302

Please sign in to comment.