go.temporal.io/server@v1.23.0/common/namespace/testconstructors.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 namespace
    26  
    27  import (
    28  	persistencespb "go.temporal.io/server/api/persistence/v1"
    29  	"go.temporal.io/server/common"
    30  )
    31  
    32  //TODO: delete this whole file and transition usages to FromPersistentState
    33  
    34  // NewLocalNamespaceForTest returns an entry with test data
    35  func NewLocalNamespaceForTest(
    36  	info *persistencespb.NamespaceInfo,
    37  	config *persistencespb.NamespaceConfig,
    38  	targetCluster string,
    39  ) *Namespace {
    40  	return &Namespace{
    41  		info:              ensureInfo(info),
    42  		config:            ensureConfig(config),
    43  		isGlobalNamespace: false,
    44  		replicationConfig: &persistencespb.NamespaceReplicationConfig{
    45  			ActiveClusterName: targetCluster,
    46  			Clusters:          []string{targetCluster},
    47  		},
    48  		failoverVersion: common.EmptyVersion,
    49  	}
    50  }
    51  
    52  // NewNamespaceForTest returns an entry with test data
    53  func NewNamespaceForTest(
    54  	info *persistencespb.NamespaceInfo,
    55  	config *persistencespb.NamespaceConfig,
    56  	isGlobalNamespace bool,
    57  	repConfig *persistencespb.NamespaceReplicationConfig,
    58  	failoverVersion int64,
    59  ) *Namespace {
    60  	return &Namespace{
    61  		info:              ensureInfo(info),
    62  		config:            ensureConfig(config),
    63  		isGlobalNamespace: isGlobalNamespace,
    64  		replicationConfig: ensureRepConfig(repConfig),
    65  		failoverVersion:   failoverVersion,
    66  	}
    67  }
    68  
    69  // newGlobalNamespaceForTest returns an entry with test data
    70  func NewGlobalNamespaceForTest(
    71  	info *persistencespb.NamespaceInfo,
    72  	config *persistencespb.NamespaceConfig,
    73  	repConfig *persistencespb.NamespaceReplicationConfig,
    74  	failoverVersion int64,
    75  ) *Namespace {
    76  	return &Namespace{
    77  		info:              ensureInfo(info),
    78  		config:            ensureConfig(config),
    79  		isGlobalNamespace: true,
    80  		replicationConfig: ensureRepConfig(repConfig),
    81  		failoverVersion:   failoverVersion,
    82  	}
    83  }
    84  
    85  func ensureInfo(proto *persistencespb.NamespaceInfo) *persistencespb.NamespaceInfo {
    86  	if proto == nil {
    87  		return &persistencespb.NamespaceInfo{}
    88  	}
    89  	return proto
    90  }
    91  
    92  func ensureConfig(proto *persistencespb.NamespaceConfig) *persistencespb.NamespaceConfig {
    93  	if proto == nil {
    94  		return &persistencespb.NamespaceConfig{}
    95  	}
    96  	return proto
    97  }
    98  
    99  func ensureRepConfig(proto *persistencespb.NamespaceReplicationConfig) *persistencespb.NamespaceReplicationConfig {
   100  	if proto == nil {
   101  		return &persistencespb.NamespaceReplicationConfig{}
   102  	}
   103  	return proto
   104  }