dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/common/config_test.go (about)

     1  //
     2  // Copyright (C) 2020 Intel Corporation
     3  // Copyright (C) 2021 IOTech Ltd
     4  //
     5  // SPDX-License-Identifier: Apache-2.0
     6  //
     7  
     8  package common
     9  
    10  import (
    11  	"encoding/json"
    12  	"testing"
    13  
    14  	"github.com/google/uuid"
    15  
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/require"
    18  
    19  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/common"
    20  )
    21  
    22  func TestNewConfigResponse(t *testing.T) {
    23  	serviceName := uuid.NewString()
    24  
    25  	type testConfig struct {
    26  		Name string
    27  		Host string
    28  		Port int
    29  	}
    30  
    31  	expected := testConfig{
    32  		Name: "UnitTest",
    33  		Host: "localhost",
    34  		Port: 8080,
    35  	}
    36  
    37  	target := NewConfigResponse(expected, serviceName)
    38  
    39  	assert.Equal(t, common.ApiVersion, target.ApiVersion)
    40  	assert.Equal(t, serviceName, target.ServiceName)
    41  
    42  	data, _ := json.Marshal(target.Config)
    43  	actual := testConfig{}
    44  	err := json.Unmarshal(data, &actual)
    45  	require.NoError(t, err)
    46  	assert.Equal(t, expected, actual)
    47  }