github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/oidext/oidext_test.go (about)

     1  // Copyright 2020 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 oidext contains oids that are not in `github.com/lib/pq/oid`
    12  // as they are not shipped by default with postgres.
    13  // As CRDB does not support extensions, we'll need to automatically assign
    14  // a few OIDs of our own.
    15  package oidext
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  
    21  	"github.com/lib/pq/oid"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestTypeName(t *testing.T) {
    26  	testCases := []struct {
    27  		o            oid.Oid
    28  		expectedName string
    29  		expectedOk   bool
    30  	}{
    31  		{oid.T_int4, "INT4", true},
    32  		{T_geometry, "GEOMETRY", true},
    33  		{oid.Oid(99988199), "", false},
    34  	}
    35  
    36  	for _, tc := range testCases {
    37  		t.Run(fmt.Sprintf("oid:%d", tc.o), func(t *testing.T) {
    38  			name, ok := TypeName(tc.o)
    39  			require.Equal(t, tc.expectedName, name)
    40  			require.Equal(t, tc.expectedOk, ok)
    41  		})
    42  	}
    43  }
    44  
    45  // TestOIDsMaxValue ensures that any predefined OID values are less than
    46  // the set maximum for OIDs.
    47  func TestOIDsMaxValue(t *testing.T) {
    48  	for oid, name := range oid.TypeName {
    49  		if oid >= CockroachPredefinedOIDMax {
    50  			t.Fatalf("oid %d for type %s greater than max %d", oid, name, CockroachPredefinedOIDMax)
    51  		}
    52  	}
    53  	for oid, name := range ExtensionTypeName {
    54  		if oid >= CockroachPredefinedOIDMax {
    55  			t.Fatalf("oid %d for type %s greater than max %d", oid, name, CockroachPredefinedOIDMax)
    56  		}
    57  	}
    58  }