github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/protectedts/ptstorage/validate_test.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package ptstorage
    12  
    13  import (
    14  	"strconv"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/protectedts/ptpb"
    18  	roachpb "github.com/cockroachdb/cockroach/pkg/roachpb"
    19  	"github.com/cockroachdb/cockroach/pkg/util/hlc"
    20  	"github.com/cockroachdb/cockroach/pkg/util/uuid"
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestValidateRecordForProtect(t *testing.T) {
    25  	spans := []roachpb.Span{
    26  		{
    27  			Key:    roachpb.Key("a"),
    28  			EndKey: roachpb.Key("b"),
    29  		},
    30  	}
    31  	for i, tc := range []struct {
    32  		r   *ptpb.Record
    33  		err error
    34  	}{
    35  		{
    36  			r: &ptpb.Record{
    37  				ID:        uuid.MakeV4(),
    38  				Timestamp: hlc.Timestamp{WallTime: 1, Logical: 1},
    39  				MetaType:  "job",
    40  				Meta:      []byte("junk"),
    41  				Spans:     spans,
    42  			},
    43  			err: nil,
    44  		},
    45  		{
    46  			r: &ptpb.Record{
    47  				Timestamp: hlc.Timestamp{WallTime: 1, Logical: 1},
    48  				MetaType:  "job",
    49  				Meta:      []byte("junk"),
    50  				Spans:     spans,
    51  			},
    52  			err: errZeroID,
    53  		},
    54  		{
    55  			r: &ptpb.Record{
    56  				ID:       uuid.MakeV4(),
    57  				MetaType: "job",
    58  				Meta:     []byte("junk"),
    59  				Spans:    spans,
    60  			},
    61  			err: errZeroTimestamp,
    62  		},
    63  		{
    64  			r: &ptpb.Record{
    65  				ID:        uuid.MakeV4(),
    66  				Timestamp: hlc.Timestamp{WallTime: 1, Logical: 1},
    67  				Meta:      []byte("junk"),
    68  				Spans:     spans,
    69  			},
    70  			err: errInvalidMeta,
    71  		},
    72  		{
    73  			r: &ptpb.Record{
    74  				ID:        uuid.MakeV4(),
    75  				Timestamp: hlc.Timestamp{WallTime: 1, Logical: 1},
    76  				MetaType:  "job",
    77  				Meta:      []byte("junk"),
    78  			},
    79  			err: errEmptySpans,
    80  		},
    81  	} {
    82  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    83  			require.Equal(t, validateRecordForProtect(tc.r), tc.err)
    84  		})
    85  	}
    86  }