-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathattribute_test.go
51 lines (44 loc) · 1.9 KB
/
attribute_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package scpb
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetAttribute(t *testing.T) {
seqElem := SequenceDependency{
TableID: 1,
ColumnID: 2,
SequenceID: 3,
}
seqElemDiff := SequenceDependency{
TableID: 1,
ColumnID: 4,
SequenceID: 3,
}
// Sanity: Validate basic string conversion, equality,
// and inequality.
expectedStr := `*scpb.SequenceDependency:{DescID: 3, DepID: 1, ColumnID: 2 }`
require.Equal(t, expectedStr, seqElem.GetAttributes().String(), "Attribute string conversion is broken.")
require.True(t, seqElem.GetAttributes().Equal(seqElem.GetAttributes()))
require.False(t, seqElem.GetAttributes().Equal(seqElemDiff.GetAttributes()))
// Sanity: Validate type references, then check if type comparisons
// work.
typeBackRef := TypeReference{TypeID: 3, DescID: 1}
expectedStr = `*scpb.TypeReference:{DescID: 3, DepID: 1 }`
require.Equal(t, expectedStr, typeBackRef.GetAttributes().String(), "Attribute string conversion is broken.")
require.False(t, seqElem.GetAttributes().Equal(typeBackRef.GetAttributes()))
require.False(t, typeBackRef.GetAttributes().Equal(seqElem.GetAttributes()))
// Sanity: Validate attribute fetching for both types.
require.Equal(t, "1", typeBackRef.GetAttributes().Get(AttributeDepID).String())
require.Equal(t, "3", typeBackRef.GetAttributes().Get(AttributeDescID).String())
require.Equal(t, "*scpb.TypeReference", typeBackRef.GetAttributes().Get(AttributeType).String())
require.Equal(t, "4", seqElemDiff.GetAttributes().Get(AttributeColumnID).String())
}