github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/managed_node_address_unit_test.go (about)

     1  //go:build all || unit
     2  // +build all unit
     3  
     4  package hedera
     5  
     6  /*-
     7   *
     8   * Hedera Go SDK
     9   *
    10   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
    11   *
    12   * Licensed under the Apache License, Version 2.0 (the "License");
    13   * you may not use this file except in compliance with the License.
    14   * You may obtain a copy of the License at
    15   *
    16   *      http://www.apache.org/licenses/LICENSE-2.0
    17   *
    18   * Unless required by applicable law or agreed to in writing, software
    19   * distributed under the License is distributed on an "AS IS" BASIS,
    20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    21   * See the License for the specific language governing permissions and
    22   * limitations under the License.
    23   *
    24   */
    25  
    26  import (
    27  	"testing"
    28  
    29  	"github.com/stretchr/testify/require"
    30  )
    31  
    32  func TestUnitManagedNodeAddressTest(t *testing.T) {
    33  	t.Parallel()
    34  
    35  	ipAddress, err := _ManagedNodeAddressFromString("35.237.200.180:50211")
    36  	require.NoError(t, err)
    37  	require.True(t, *ipAddress.address == "35.237.200.180")
    38  	require.True(t, ipAddress.port == 50211)
    39  	require.True(t, ipAddress._String() == "35.237.200.180:50211")
    40  
    41  	ipAddressSecure := ipAddress._ToSecure()
    42  	require.True(t, *ipAddressSecure.address == "35.237.200.180")
    43  	require.True(t, ipAddressSecure.port == 50212)
    44  	require.True(t, ipAddressSecure._String() == "35.237.200.180:50212")
    45  
    46  	ipAddressInsecure := ipAddressSecure._ToInsecure()
    47  	require.True(t, *ipAddressInsecure.address == "35.237.200.180")
    48  	require.True(t, ipAddressInsecure.port == 50211)
    49  	require.True(t, ipAddressInsecure._String() == "35.237.200.180:50211")
    50  
    51  	urlAddress, err := _ManagedNodeAddressFromString("0.testnet.hedera.com:50211")
    52  	require.NoError(t, err)
    53  	require.True(t, *urlAddress.address == "0.testnet.hedera.com")
    54  	require.True(t, urlAddress.port == 50211)
    55  	require.True(t, urlAddress._String() == "0.testnet.hedera.com:50211")
    56  
    57  	urlAddressSecure := urlAddress._ToSecure()
    58  	require.True(t, *urlAddressSecure.address == "0.testnet.hedera.com")
    59  	require.True(t, urlAddressSecure.port == 50212)
    60  	require.True(t, urlAddressSecure._String() == "0.testnet.hedera.com:50212")
    61  
    62  	urlAddressInsecure := urlAddressSecure._ToInsecure()
    63  	require.True(t, *urlAddressInsecure.address == "0.testnet.hedera.com")
    64  	require.True(t, urlAddressInsecure.port == 50211)
    65  	require.True(t, urlAddressInsecure._String() == "0.testnet.hedera.com:50211")
    66  
    67  	mirrorNodeAddress, err := _ManagedNodeAddressFromString("hcs.mainnet.mirrornode.hedera.com:50211")
    68  	require.NoError(t, err)
    69  	require.True(t, *mirrorNodeAddress.address == "hcs.mainnet.mirrornode.hedera.com")
    70  	require.True(t, mirrorNodeAddress.port == 50211)
    71  	require.True(t, mirrorNodeAddress._String() == "hcs.mainnet.mirrornode.hedera.com:50211")
    72  
    73  	mirrorNodeAddressSecure := mirrorNodeAddress._ToSecure()
    74  	require.True(t, *mirrorNodeAddressSecure.address == "hcs.mainnet.mirrornode.hedera.com")
    75  	require.True(t, mirrorNodeAddressSecure.port == 50212)
    76  	require.True(t, mirrorNodeAddressSecure._String() == "hcs.mainnet.mirrornode.hedera.com:50212")
    77  
    78  	mirrorNodeAddressInsecure := mirrorNodeAddressSecure._ToInsecure()
    79  	require.True(t, *mirrorNodeAddressInsecure.address == "hcs.mainnet.mirrornode.hedera.com")
    80  	require.True(t, mirrorNodeAddressInsecure.port == 50211)
    81  	require.True(t, mirrorNodeAddressInsecure._String() == "hcs.mainnet.mirrornode.hedera.com:50211")
    82  
    83  	_, err = _ManagedNodeAddressFromString("this is a random string with spaces:443")
    84  	require.Error(t, err)
    85  
    86  	_, err = _ManagedNodeAddressFromString("hcs.mainnet.mirrornode.hedera.com:notarealport")
    87  	require.Error(t, err)
    88  }