...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package config_test
18
19 import (
20 "encoding/json"
21 "testing"
22
23 "solace.dev/go/messaging/pkg/solace/config"
24 )
25
26 var receiverProperties = config.ReceiverPropertyMap{
27 config.ReceiverPropertyDirectBackPressureBufferCapacity: float64(10),
28 config.ReceiverPropertyDirectBackPressureStrategy: "default",
29 }
30
31 var receiverPropertiesJSON = `{"solace":{"messaging":{"receiver":{"direct":{"back-pressure":{"buffer-capacity":10,"strategy":"default"}}}}}}`
32
33 func TestMessageReceiverPropertiesCopy(t *testing.T) {
34 myProperties := receiverProperties.GetConfiguration()
35 myProperties[config.ReceiverPropertyDirectBackPressureStrategy] = "test"
36 if receiverProperties[config.ReceiverPropertyDirectBackPressureStrategy] == "test" {
37 t.Error("map was passed by reference, not copied on GetConfiguration")
38 }
39 }
40 func TestMessageReceiverPropertiesFromJSON(t *testing.T) {
41 output := make(config.ReceiverPropertyMap)
42 json.Unmarshal([]byte(receiverPropertiesJSON), &output)
43 for key, val := range output {
44 expectedVal, ok := receiverProperties[key]
45 if !ok {
46 t.Errorf("did not expect key %s", key)
47 }
48 if expectedVal != val {
49 t.Errorf("expected %s to equal %s", val, expectedVal)
50 }
51 }
52 for key := range receiverProperties {
53 _, ok := output[key]
54 if !ok {
55 t.Errorf("expected key %s to be present", key)
56 }
57 }
58 }
59
60 func TestMessageReceiverPropertiesToJSON(t *testing.T) {
61 output, err := json.Marshal(receiverProperties)
62 if err != nil {
63 t.Errorf("expected error to be nil, got %s", err)
64 }
65 if len(output) != len(receiverPropertiesJSON) {
66 t.Errorf("expected output '%s' to equal '%s'", output, receiverPropertiesJSON)
67 }
68 for i, b := range output {
69 if receiverPropertiesJSON[i] != b {
70 t.Errorf("expected output '%s' to equal '%s'", output, receiverPropertiesJSON)
71 }
72 }
73 }
74