...

Source file src/github.com/jackc/pgtype/tid_test.go

Documentation: github.com/jackc/pgtype

     1  package pgtype_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/jackc/pgtype"
     8  	"github.com/jackc/pgtype/testutil"
     9  )
    10  
    11  func TestTIDTranscode(t *testing.T) {
    12  	testutil.TestSuccessfulTranscode(t, "tid", []interface{}{
    13  		&pgtype.TID{BlockNumber: 42, OffsetNumber: 43, Status: pgtype.Present},
    14  		&pgtype.TID{BlockNumber: 4294967295, OffsetNumber: 65535, Status: pgtype.Present},
    15  		&pgtype.TID{Status: pgtype.Null},
    16  	})
    17  }
    18  
    19  func TestTIDAssignTo(t *testing.T) {
    20  	var s string
    21  	var sp *string
    22  
    23  	simpleTests := []struct {
    24  		src      pgtype.TID
    25  		dst      interface{}
    26  		expected interface{}
    27  	}{
    28  		{src: pgtype.TID{BlockNumber: 42, OffsetNumber: 43, Status: pgtype.Present}, dst: &s, expected: "(42,43)"},
    29  		{src: pgtype.TID{BlockNumber: 4294967295, OffsetNumber: 65535, Status: pgtype.Present}, dst: &s, expected: "(4294967295,65535)"},
    30  	}
    31  
    32  	for i, tt := range simpleTests {
    33  		err := tt.src.AssignTo(tt.dst)
    34  		if err != nil {
    35  			t.Errorf("%d: %v", i, err)
    36  		}
    37  
    38  		if dst := reflect.ValueOf(tt.dst).Elem().Interface(); dst != tt.expected {
    39  			t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
    40  		}
    41  	}
    42  
    43  	pointerAllocTests := []struct {
    44  		src      pgtype.TID
    45  		dst      interface{}
    46  		expected interface{}
    47  	}{
    48  		{src: pgtype.TID{BlockNumber: 42, OffsetNumber: 43, Status: pgtype.Present}, dst: &sp, expected: "(42,43)"},
    49  		{src: pgtype.TID{BlockNumber: 4294967295, OffsetNumber: 65535, Status: pgtype.Present}, dst: &sp, expected: "(4294967295,65535)"},
    50  	}
    51  
    52  	for i, tt := range pointerAllocTests {
    53  		err := tt.src.AssignTo(tt.dst)
    54  		if err != nil {
    55  			t.Errorf("%d: %v", i, err)
    56  		}
    57  
    58  		if dst := reflect.ValueOf(tt.dst).Elem().Elem().Interface(); dst != tt.expected {
    59  			t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
    60  		}
    61  	}
    62  }
    63  
    64  

View as plain text