Categorygithub.com/megur0/testutil
modulepackage
0.0.0-20250125093040-40a09a0676d0
Repository: https://github.com/megur0/testutil.git
Documentation: pkg.go.dev

# README

テストで利用するutil関数群

  • AssertJsonExactをはじめとしたgo testの際に利用する関数群

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
文字列のjsonを受け取ってmapにしてDiffを取る。 完全一致比較。(余計なフィールドがあってもエラーとなり、不足してもエラーとなる) 現状、最上位が{}で囲まれているJSONのみに対応している これは、json.Unmarshalした際に、最上位がmap[string]interface{}となるもので、 例えば、[0,1,2,3] や 3 はエラーとなる。 ignoreValuesで指定したフィールドはデフォルト値とすることができる。 ignoreValuesはドット区切りで指定する。(例)data.entity.user.id したがってフィールドが存在することをチェックしたいが値自体には関心がない場合に、 ignoreValuesを指定した上で、expectJsonの対象のフィールドを stringなら"", intなら0, boolならfalse, に指定すれば良い。 (24/8/17対応)ignoreValuesは途中が配列の場合は全ての子要素に適用される。 例えば"data.id"のように指定した際に、{"data": [{"id":1}, {"id":2}, ...]}の全ての子要素に 適用される。ただし{"data": [[ {"id":1} ]] }のように入れ子の配列には適用されない。 ブロックを指定(例えば、data.entity.userとした際にuser内に各種キーが含まれる場合)した場合は、その中身が再帰的に全てデフォルト値になる。 (user内のプロパティが消えて空のマップとなるわけではなく、中のキーそれぞれがデフォルト値になる点に注意。) *.fieldNameのように指定すると階層に関係なくすべての"fieldName" をデフォルト値にする。(ただ、mapを全走査するので効率は悪い。) *は必ず先頭に置いて直後にフィールドを指定する必要がある。 aaa.*.fieldNameや、*.aaa.fieldNameといった指定はできない。 日時はJSON上は単なる文字列のため、ゼロバリューは空文字となる。.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author