-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tm2/std)!: use snake_case JSON fields for MemFile and MemPackage (#…
…2019) This PR changes the MemFile and MemPackage to use `snake_case` fields for their JSON key names. This matches what all other objects in transactions do. A new test ensures that no transaction objects within the VM keeper have uppercase runes within their exported json fields. **BREAKING CHANGE:** old `m_addpkg` and `m_run` transactions will stop working. Clients will need to update accordingly, and this change needs to be synced like #1939. cc/ @zivkovicmilos @gnolang/berty @gnolang/onbloc --------- Co-authored-by: Miloš Živković <[email protected]>
- Loading branch information
1 parent
4dc2712
commit 3901e7e
Showing
3 changed files
with
55 additions
and
6 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,49 @@ | ||
package vm | ||
|
||
import ( | ||
"reflect" | ||
"strings" | ||
"testing" | ||
"unicode" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestJSONSnakeCase(t *testing.T) { | ||
t.Parallel() | ||
for _, typ := range Package.Types { | ||
assertJSONSnakeCase(t, typ.Type) | ||
} | ||
} | ||
|
||
func assertJSONSnakeCase(t *testing.T, typ reflect.Type) { | ||
t.Helper() | ||
|
||
switch typ.Kind() { | ||
case reflect.Array, reflect.Slice, reflect.Pointer: | ||
assertJSONSnakeCase(t, typ.Elem()) | ||
case reflect.Map: | ||
assertJSONSnakeCase(t, typ.Key()) | ||
assertJSONSnakeCase(t, typ.Elem()) | ||
case reflect.Struct: | ||
for i := 0; i < typ.NumField(); i++ { | ||
fld := typ.Field(i) | ||
if !fld.IsExported() { | ||
continue | ||
} | ||
jt := fld.Tag.Get("json") | ||
if jt == "" { | ||
if fld.Anonymous { | ||
assertJSONSnakeCase(t, fld.Type) | ||
continue | ||
} | ||
t.Errorf("field %s.%s does not have a json tag but is exported", typ.Name(), fld.Name) | ||
continue | ||
} | ||
has := strings.ContainsFunc(jt, unicode.IsUpper) | ||
assert.False(t, has, | ||
"field %s.%s contains uppercase symbols in json tag", typ.Name(), fld.Name) | ||
assertJSONSnakeCase(t, fld.Type) | ||
} | ||
} | ||
} |
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