cast_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2021 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cast
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func TestMapConvert_Funcs(t *testing.T) {
  20. source := map[interface{}]interface{}{
  21. "QUERY_TABLE": "VBAP",
  22. "ROWCOUNT": 10,
  23. "FIELDS": []interface{}{
  24. map[interface{}]interface{}{"FIELDNAME": "MANDT"},
  25. map[interface{}]interface{}{"FIELDNAME": "VBELN"},
  26. map[interface{}]interface{}{"FIELDNAME": "POSNR"},
  27. },
  28. }
  29. exp := map[string]interface{}{
  30. "QUERY_TABLE": "VBAP",
  31. "ROWCOUNT": 10,
  32. "FIELDS": []interface{}{
  33. map[string]interface{}{"FIELDNAME": "MANDT"},
  34. map[string]interface{}{"FIELDNAME": "VBELN"},
  35. map[string]interface{}{"FIELDNAME": "POSNR"},
  36. },
  37. }
  38. got := ConvertMap(source)
  39. if !reflect.DeepEqual(exp, got) {
  40. t.Errorf("result mismatch:\n\nexp=%s\n\ngot=%s\n\n", exp, got)
  41. }
  42. }