-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gosimlog: store unknown fields and show in viewer
- Loading branch information
1 parent
5c5d227
commit 75f05a2
Showing
3 changed files
with
140 additions
and
1 deletion.
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,48 @@ | ||
package gosimlog_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
||
"github.com/jellevandenhooff/gosim/internal/gosimlog" | ||
) | ||
|
||
func TestUnmarshalLog(t *testing.T) { | ||
testcases := []struct { | ||
json string | ||
expected *gosimlog.Log | ||
}{ | ||
{ | ||
json: `{ | ||
"msg": "hello", | ||
"extra": "1", | ||
"extra2": "2" | ||
}`, | ||
expected: &gosimlog.Log{ | ||
Msg: "hello", | ||
Unknown: []gosimlog.UnknownField{ | ||
{ | ||
Key: "extra", | ||
Value: `"1"`, | ||
}, | ||
{ | ||
Key: "extra2", | ||
Value: `"2"`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
var got gosimlog.Log | ||
if err := json.Unmarshal([]byte(tc.json), &got); err != nil { | ||
t.Error(err) | ||
} | ||
if diff := cmp.Diff(&got, tc.expected); diff != "" { | ||
t.Errorf("unexpected diff unmarshaling %q: %s", tc.json, diff) | ||
} | ||
} | ||
} |
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