...

Source file src/solace.dev/go/messaging/pkg/solace/config/message_receiver_properties_test.go

Documentation: solace.dev/go/messaging/pkg/solace/config

     1  // pubsubplus-go-client
     2  //
     3  // Copyright 2021-2025 Solace Corporation. All rights reserved.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  // http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    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