Skip to content

Commit

Permalink
add test for resetting field values
Browse files Browse the repository at this point in the history
  • Loading branch information
alovak committed Oct 25, 2024
1 parent 3f9cf01 commit 62c0e4f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func TestMessage(t *testing.T) {
require.Equal(t, wantMsg, rawMsg)
})

t.Run("Clone and reset fields", func(t *testing.T) {
t.Run("Clone, set zero values and reset fields", func(t *testing.T) {
type TestISOF3Data struct {
F1 *field.String
F2 *field.String
Expand Down Expand Up @@ -413,17 +413,23 @@ func TestMessage(t *testing.T) {

// reset the fields
err = clone.Marshal(&struct {
F2 *string `iso8583:"2,keepzero"`
F2 *field.String `iso8583:",keepzero"`
F3 *struct {
F2 *string `iso8583:"2,keepzero"`
} `iso8583:"3,keepzero"`
F2 *field.String `iso8583:",keepzero"`
} `iso8583:",keepzero"`
}{})
require.NoError(t, err)

// check that the fields are reset
// check that the field values are set to zero values
data = &ISO87Data{}
require.NoError(t, clone.Unmarshal(data))

// check that fields are set
require.NotNil(t, data.F2)
require.NotNil(t, data.F3)
require.NotNil(t, data.F3.F2)

// check the zero values
require.Equal(t, "", data.F2.Value())
require.Equal(t, "", data.F3.F2.Value())

Expand Down Expand Up @@ -1765,7 +1771,7 @@ func TestMessageClone(t *testing.T) {
// check if the PAN is reset
require.Equal(t, "", responseData.F2.Value())
// check if the F55.F9A is reset
require.Equal(t, "210720", responseData.F55.F9A.Value())
require.Equal(t, "", responseData.F55.F9A.Value())
}

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

0 comments on commit 62c0e4f

Please sign in to comment.