datacopy_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Public Domain Software
  3. *
  4. * I (Matthias Ladkau) am the author of the source code in this file.
  5. * I have placed the source code in this file in the public domain.
  6. *
  7. * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. package datautil
  10. import (
  11. "testing"
  12. "devt.de/krotik/common/testutil"
  13. )
  14. func TestMergeMaps(t *testing.T) {
  15. m := MergeMaps(map[string]interface{}{
  16. "a": 1,
  17. "b": 2,
  18. }, map[string]interface{}{
  19. "b": 3,
  20. "c": 4,
  21. })
  22. if len(m) != 3 {
  23. t.Error("Unexpected number of result entries:", len(m))
  24. return
  25. }
  26. if m["a"] != 1 || m["b"] != 3 || m["c"] != 4 {
  27. t.Error("Unexpected entries:", m)
  28. return
  29. }
  30. }
  31. func TestCopyObject(t *testing.T) {
  32. var ret2 string
  33. if err := CopyObject("test", &ret2); err != nil {
  34. t.Error(err)
  35. return
  36. }
  37. // Test encoding errors
  38. var ret3 testutil.GobTestObject
  39. gobtest := &testutil.GobTestObject{Name: "test", EncErr: true, DecErr: false}
  40. if err := CopyObject(gobtest, &ret3); err == nil || err.Error() != "Encode error" {
  41. t.Error("Unexpected result:", err)
  42. return
  43. }
  44. gobtest = &testutil.GobTestObject{Name: "test", EncErr: false, DecErr: false}
  45. ret3 = testutil.GobTestObject{Name: "test", EncErr: false, DecErr: true}
  46. if err := CopyObject(gobtest, &ret3); err == nil || err.Error() != "Decode error" {
  47. t.Error("Unexpected result:", err)
  48. return
  49. }
  50. ret3 = testutil.GobTestObject{Name: "test", EncErr: true, DecErr: false}
  51. if err := CopyObject(&ret3, gobtest); err == nil || err.Error() != "Encode error" {
  52. t.Error("Unexpected result:", err)
  53. return
  54. }
  55. ret3 = testutil.GobTestObject{Name: "test", EncErr: false, DecErr: false}
  56. gobtest = &testutil.GobTestObject{Name: "test", EncErr: false, DecErr: true}
  57. if err := CopyObject(&ret3, gobtest); err == nil || err.Error() != "Decode error" {
  58. t.Error("Unexpected result:", err)
  59. return
  60. }
  61. }