github.com/songzhibin97/gkit@v1.2.13/tools/deepcopy/deepcopy_test.go (about)

     1  package deepcopy
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func Test_deepCopy(t *testing.T) {
     9  	type (
    10  		mock struct {
    11  			Name      string
    12  			Age       int
    13  			Money     float64
    14  			Attribute map[string]string
    15  			Friends   []string
    16  		}
    17  	)
    18  	var (
    19  		m1 = &mock{
    20  			Name:      "gkit",
    21  			Age:       21,
    22  			Money:     10.01,
    23  			Attribute: map[string]string{"job": "engineer"},
    24  			Friends:   []string{"one", "two", "three"},
    25  		}
    26  		m2 = mock{
    27  			Name:      "tikg",
    28  			Age:       12,
    29  			Money:     1.01,
    30  			Attribute: map[string]string{"engineer": "job"},
    31  			Friends:   []string{"three", "two", "one"},
    32  		}
    33  	)
    34  	err := DeepCopy(m1, &m2)
    35  	assert.NoError(t, err)
    36  	assert.Equal(t, *m1, m2)
    37  }