github.com/sacloud/iaas-api-go@v1.12.0/fake/functions_test.go (about)

     1  // Copyright 2022-2023 The sacloud/iaas-api-go Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package fake
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  type SourceStruct struct {
    24  	Field1  string
    25  	Field1e string
    26  	Field2  string
    27  	Field2e string
    28  	Field3  int
    29  	Field3e int
    30  	Field4  []string
    31  	Field4e []string
    32  	Field5  interface{}
    33  	Field5e interface{}
    34  }
    35  
    36  type DestStruct struct {
    37  	Field1 string
    38  	Field2 string
    39  	Field3 int
    40  	Field4 []string
    41  	Field5 interface{}
    42  }
    43  
    44  func TestCopy(t *testing.T) {
    45  	tests := []struct {
    46  		input  *SourceStruct
    47  		output *DestStruct
    48  	}{
    49  		{
    50  			input: &SourceStruct{
    51  				Field1:  "field1",
    52  				Field1e: "field1",
    53  				Field2:  "field2",
    54  				Field2e: "field2",
    55  				Field3:  3,
    56  				Field3e: 3,
    57  				Field4:  []string{"f", "i", "e", "l", "d", "4"},
    58  				Field4e: []string{"f", "i", "e", "l", "d", "4"},
    59  				Field5:  "field5",
    60  				Field5e: "field5",
    61  			},
    62  			output: &DestStruct{
    63  				Field1: "field1",
    64  				Field2: "field2",
    65  				Field3: 3,
    66  				Field4: []string{"f", "i", "e", "l", "d", "4"},
    67  				Field5: "field5",
    68  			},
    69  		},
    70  	}
    71  
    72  	for _, tt := range tests {
    73  		dest := &DestStruct{}
    74  		copySameNameField(tt.input, dest)
    75  		require.Equal(t, tt.output, dest)
    76  	}
    77  }