forked from faisaltheparttimecoder/mock-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datatypes_test.go
120 lines (117 loc) · 2.51 KB
/
datatypes_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"reflect"
"testing"
)
// Test: SupportedDataTypes, this function is used when user ask to create random tables with
// random datatypes
func TestSupportedDataTypes(t *testing.T) {
tests := struct {
name string
want []string
}{
"all_supported_datatypes", []string{
"int8,",
"bigint,",
"bigserial,",
"integer,",
"smallint,",
"smallserial,",
"serial,",
"oid,",
"real,",
"double precision,",
"numeric(4,2),",
"bit(1),",
"bit varying(4),",
"boolean,",
"character(10),",
"character varying(10),",
"text,",
"inet,",
"macaddr,",
"cidr,",
"interval,",
"date,",
"time without time zone,",
"time with time zone,",
"timestamp with time zone,",
"timestamp without time zone,",
"timestamp(6) with time zone,",
"timestamp(6) without time zone,",
"money,",
"json,",
"jsonb,",
"xml,",
"tsquery,",
"tsvector,",
"box,",
"circle,",
"line,",
"lseg,",
"path,",
"polygon,",
"point,",
"bytea,",
"pg_lsn,",
"txid_snapshot,",
"uuid,",
"smallint[],",
"integer[],",
"bigint[],",
"character(10)[],",
"character varying(10)[],",
"bit(10)[],",
"bit varying(4)[],",
"numeric[],",
"numeric(5,3)[],",
"real[],",
"double precision[],",
"money[],",
"time without time zone[],",
"interval[],",
"date[],",
"time with time zone[],",
"timestamp with time zone[],",
"timestamp without time zone[],",
"text[],",
"boolean[],",
"inet[],",
"macaddr[],",
"cidr[],",
"uuid[],",
"txid_snapshot[],",
"pg_lsn[],",
"tsquery[],",
"tsvector[],",
"box[],",
"circle[],",
"line[],",
"lseg[],",
"path[],",
"polygon[],",
"point[],",
"json[],",
"jsonb[],",
"xml[],",
},
}
t.Run(tests.name, func(t *testing.T) {
s := SupportedDataTypes()
if !reflect.DeepEqual(s, tests.want) {
t.Errorf("TestSupportedDataTypes() = %v, want %v", s, tests.want)
}
})
}
// Test: supportedDataTypesDemoTable, create the table of all the support datatype
func TestSupportedDataTypesDemoTable(t *testing.T) {
t.Run("create_table_with_all_supported_datatypes", func(t *testing.T) {
setDatabaseConfigForTest()
if err := supportedDataTypesDemoTable(); err != nil {
t.Errorf("TestSupportedDataTypesDemoTable, failed to create table, err: %v", err)
}
if _, err := ExecuteDB("SELECT 'public.supported_datatypes'::regclass;"); err != nil {
t.Errorf("TestSupportedDataTypesDemoTable, had to create a table but its not found in the database")
}
})
}