go.temporal.io/server@v1.23.0/common/persistence/history_branch_util_test.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package persistence
    26  
    27  import (
    28  	"testing"
    29  
    30  	"github.com/stretchr/testify/require"
    31  	"github.com/stretchr/testify/suite"
    32  
    33  	persistencespb "go.temporal.io/server/api/persistence/v1"
    34  	"go.temporal.io/server/common/primitives"
    35  )
    36  
    37  type (
    38  	historyBranchUtilSuite struct {
    39  		suite.Suite
    40  		*require.Assertions
    41  	}
    42  )
    43  
    44  func TestHistoryBranchUtilSuite(t *testing.T) {
    45  	s := new(historyBranchUtilSuite)
    46  	suite.Run(t, s)
    47  }
    48  
    49  func (s *historyBranchUtilSuite) SetupSuite() {
    50  }
    51  
    52  func (s *historyBranchUtilSuite) TearDownSuite() {
    53  }
    54  
    55  func (s *historyBranchUtilSuite) SetupTest() {
    56  	s.Assertions = require.New(s.T())
    57  }
    58  
    59  func (s *historyBranchUtilSuite) TearDownTest() {
    60  }
    61  
    62  func (s *historyBranchUtilSuite) TestHistoryBranchUtil() {
    63  	var historyBranchUtil HistoryBranchUtil = &HistoryBranchUtilImpl{}
    64  
    65  	treeID0 := primitives.NewUUID().String()
    66  	branchID0 := primitives.NewUUID().String()
    67  	ancestors := []*persistencespb.HistoryBranchRange(nil)
    68  	branchToken0, err := NewHistoryBranch(treeID0, &branchID0, ancestors)
    69  	s.NoError(err)
    70  
    71  	branchInfo0, err := historyBranchUtil.ParseHistoryBranchInfo(branchToken0)
    72  	s.NoError(err)
    73  	s.Equal(treeID0, branchInfo0.TreeId)
    74  	s.Equal(branchID0, branchInfo0.BranchId)
    75  	s.Equal(ancestors, branchInfo0.Ancestors)
    76  
    77  	treeID1 := primitives.NewUUID().String()
    78  	branchID1 := primitives.NewUUID().String()
    79  	branchToken1, err := historyBranchUtil.UpdateHistoryBranchInfo(
    80  		branchToken0,
    81  		&persistencespb.HistoryBranch{
    82  			TreeId:    treeID1,
    83  			BranchId:  branchID1,
    84  			Ancestors: ancestors,
    85  		})
    86  	s.NoError(err)
    87  
    88  	branchInfo1, err := historyBranchUtil.ParseHistoryBranchInfo(branchToken1)
    89  	s.NoError(err)
    90  	s.Equal(treeID1, branchInfo1.TreeId)
    91  	s.Equal(branchID1, branchInfo1.BranchId)
    92  	s.Equal(ancestors, branchInfo1.Ancestors)
    93  }