github.com/drone/runner-go@v1.12.0/internal/merge_test.go (about)

     1  // Copyright 2019 Drone.IO Inc. All rights reserved.
     2  // Use of this source code is governed by the Polyform License
     3  // that can be found in the LICENSE file.
     4  
     5  package internal
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/drone/drone-go/drone"
    11  
    12  	"github.com/google/go-cmp/cmp"
    13  )
    14  
    15  func TestMergeStep(t *testing.T) {
    16  	src := &drone.Step{
    17  		ID:      1,
    18  		StageID: 2,
    19  		Started: 1561256095,
    20  		Stopped: 1561256092,
    21  		Version: 1,
    22  	}
    23  	dst := &drone.Step{
    24  		ID: 1,
    25  	}
    26  
    27  	MergeStep(src, dst)
    28  	if src == dst {
    29  		t.Errorf("Except copy of step, got reference")
    30  	}
    31  
    32  	after := &drone.Step{
    33  		ID:      1,
    34  		StageID: 2,
    35  		Started: 1561256095,
    36  		Stopped: 1561256092,
    37  		Version: 1,
    38  	}
    39  	if diff := cmp.Diff(after, src); diff != "" {
    40  		t.Errorf("Expect src not modified")
    41  		t.Log(diff)
    42  	}
    43  	if diff := cmp.Diff(after, dst); diff != "" {
    44  		t.Errorf("Expect src values copied to dst")
    45  		t.Log(diff)
    46  	}
    47  }
    48  
    49  func TestMergeStage(t *testing.T) {
    50  	dst := &drone.Stage{
    51  		ID: 1,
    52  		Steps: []*drone.Step{
    53  			{
    54  				ID: 1,
    55  			},
    56  		},
    57  	}
    58  	src := &drone.Stage{
    59  		ID:      1,
    60  		Created: 1561256095,
    61  		Updated: 1561256092,
    62  		Version: 1,
    63  		Steps: []*drone.Step{
    64  			{
    65  				ID:      1,
    66  				StageID: 2,
    67  				Started: 1561256095,
    68  				Stopped: 1561256092,
    69  				Version: 1,
    70  			},
    71  		},
    72  	}
    73  
    74  	MergeStage(src, dst)
    75  	if src == dst {
    76  		t.Errorf("Except copy of stage, got reference")
    77  	}
    78  
    79  	after := &drone.Stage{
    80  		ID:      1,
    81  		Created: 1561256095,
    82  		Updated: 1561256092,
    83  		Version: 1,
    84  		Steps: []*drone.Step{
    85  			{
    86  				ID:      1,
    87  				StageID: 2,
    88  				Started: 1561256095,
    89  				Stopped: 1561256092,
    90  				Version: 1,
    91  			},
    92  		},
    93  	}
    94  	if diff := cmp.Diff(after, dst); diff != "" {
    95  		t.Errorf("Expect src values copied to dst")
    96  		t.Log(diff)
    97  	}
    98  }