forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkpoint: Implemented marshal funcs and added test
Signed-off-by: Annanay <annanayagarwal@gmail.com>
- Loading branch information
Showing
2 changed files
with
87 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,55 @@ | ||
package overrides | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func TestListToMapMarshalOperations(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
original ListToMap | ||
marshalledYAML string | ||
marshalledJSON string | ||
}{ | ||
{ | ||
name: "empty map", | ||
original: ListToMap{}, | ||
marshalledYAML: "", | ||
marshalledJSON: "[]", | ||
}, | ||
{ | ||
name: "map with entries", | ||
original: ListToMap{ | ||
m: map[string]struct{}{ | ||
"foo": {}, | ||
}, | ||
}, | ||
marshalledYAML: "- foo", | ||
marshalledJSON: "[\"foo\"]", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
bytes, err := yaml.Marshal(tc.original) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.marshalledYAML, string(bytes)) | ||
|
||
l := ListToMap{} | ||
assert.NoError(t, yaml.Unmarshal([]byte(tc.marshalledYAML), &l)) | ||
assert.Equal(t, tc.original, l) | ||
|
||
bytes, err = json.Marshal(tc.original) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tc.marshalledJSON, string(bytes)) | ||
|
||
l2 := ListToMap{} | ||
assert.NoError(t, json.Unmarshal([]byte(tc.marshalledJSON), &l2)) | ||
assert.Equal(t, tc.original, l2) | ||
}) | ||
} | ||
} |