|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package types |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | +) |
| 25 | + |
| 26 | +func TestTableMeta_GetPrimaryKeyTypeStrMap(t *testing.T) { |
| 27 | + type fields struct { |
| 28 | + TableName string |
| 29 | + Columns map[string]ColumnMeta |
| 30 | + Indexs map[string]IndexMeta |
| 31 | + ColumnNames []string |
| 32 | + } |
| 33 | + |
| 34 | + tests := []struct { |
| 35 | + name string |
| 36 | + fields fields |
| 37 | + want map[string]string |
| 38 | + }{ |
| 39 | + {name: "test-1", fields: fields{TableName: "test", Indexs: map[string]IndexMeta{ |
| 40 | + "id": { |
| 41 | + Name: "id", |
| 42 | + ColumnName: "id", |
| 43 | + IType: IndexTypePrimaryKey, |
| 44 | + Columns: []ColumnMeta{ |
| 45 | + { |
| 46 | + ColumnName: "id", |
| 47 | + DatabaseTypeString: "BIGINT", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }}, want: map[string]string{ |
| 52 | + "id": "BIGINT", |
| 53 | + }}, |
| 54 | + } |
| 55 | + for _, tt := range tests { |
| 56 | + t.Run(tt.name, func(t *testing.T) { |
| 57 | + m := TableMeta{ |
| 58 | + TableName: tt.fields.TableName, |
| 59 | + Columns: tt.fields.Columns, |
| 60 | + Indexs: tt.fields.Indexs, |
| 61 | + ColumnNames: tt.fields.ColumnNames, |
| 62 | + } |
| 63 | + got, err := m.GetPrimaryKeyTypeStrMap() |
| 64 | + assert.Nil(t, err) |
| 65 | + assert.Equal(t, tt.want, got) |
| 66 | + }) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func TestTableMeta_GetPrimaryKeyType(t *testing.T) { |
| 71 | + type fields struct { |
| 72 | + TableName string |
| 73 | + Columns map[string]ColumnMeta |
| 74 | + Indexs map[string]IndexMeta |
| 75 | + ColumnNames []string |
| 76 | + } |
| 77 | + tests := []struct { |
| 78 | + name string |
| 79 | + fields fields |
| 80 | + want int32 |
| 81 | + }{ |
| 82 | + {name: "test-1", fields: fields{TableName: "test", Indexs: map[string]IndexMeta{ |
| 83 | + "id": { |
| 84 | + Name: "id", |
| 85 | + ColumnName: "id", |
| 86 | + IType: IndexTypePrimaryKey, |
| 87 | + Columns: []ColumnMeta{ |
| 88 | + { |
| 89 | + ColumnName: "id", |
| 90 | + DatabaseTypeString: "BIGINT", |
| 91 | + DatabaseType: GetSqlDataType("BIGINT"), |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + }}, want: GetSqlDataType("BIGINT")}, |
| 96 | + } |
| 97 | + for _, tt := range tests { |
| 98 | + t.Run(tt.name, func(t *testing.T) { |
| 99 | + m := TableMeta{ |
| 100 | + TableName: tt.fields.TableName, |
| 101 | + Columns: tt.fields.Columns, |
| 102 | + Indexs: tt.fields.Indexs, |
| 103 | + ColumnNames: tt.fields.ColumnNames, |
| 104 | + } |
| 105 | + got, err := m.GetPrimaryKeyType() |
| 106 | + assert.Nil(t, err) |
| 107 | + assert.Equalf(t, tt.want, got, "GetPrimaryKeyType()") |
| 108 | + }) |
| 109 | + } |
| 110 | +} |
0 commit comments