Browse Source

add more tests

xormplus 8 years ago
parent
commit
e931b156c0
4 changed files with 77 additions and 1 deletions
  1. 26 0
      helpers_test.go
  2. 2 0
      session.go
  3. 1 1
      session_delete_test.go
  4. 48 0
      tag_test.go

+ 26 - 0
helpers_test.go

@@ -0,0 +1,26 @@
+// Copyright 2017 The Xorm Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package xorm
+
+import "testing"
+
+func TestSplitTag(t *testing.T) {
+	var cases = []struct {
+		tag  string
+		tags []string
+	}{
+		{"not null default '2000-01-01 00:00:00' TIMESTAMP", []string{"not", "null", "default", "'2000-01-01 00:00:00'", "TIMESTAMP"}},
+		{"TEXT", []string{"TEXT"}},
+		{"default('2000-01-01 00:00:00')", []string{"default('2000-01-01 00:00:00')"}},
+		{"json  binary", []string{"json", "binary"}},
+	}
+
+	for _, kase := range cases {
+		tags := splitTag(kase.tag)
+		if !sliceEq(tags, kase.tags) {
+			t.Fatalf("[%d]%v is not equal [%d]%v", len(tags), tags, len(kase.tags), kase.tags)
+		}
+	}
+}

+ 2 - 0
session.go

@@ -52,6 +52,8 @@ type Session struct {
 	lastSQLArgs []interface{}
 	lastSQLArgs []interface{}
 
 
 	rollbackSavePointID string
 	rollbackSavePointID string
+
+	err error
 }
 }
 
 
 // Clone copy all the session's content and return a new session.
 // Clone copy all the session's content and return a new session.

+ 1 - 1
session_delete_test.go

@@ -15,7 +15,7 @@ func TestDelete(t *testing.T) {
 	assert.NoError(t, prepareEngine())
 	assert.NoError(t, prepareEngine())
 
 
 	type UserinfoDelete struct {
 	type UserinfoDelete struct {
-		Uid   int64
+		Uid   int64 `xorm:"id pk not null autoincr"`
 		IsMan bool
 		IsMan bool
 	}
 	}
 
 

+ 48 - 0
tag_test.go

@@ -187,3 +187,51 @@ func TestLowerCase(t *testing.T) {
 		panic(err)
 		panic(err)
 	}
 	}
 }
 }
+
+func TestAutoIncrTag(t *testing.T) {
+	assert.NoError(t, prepareEngine())
+
+	type TestAutoIncr1 struct {
+		Id int64
+	}
+
+	tb := testEngine.TableInfo(new(TestAutoIncr1))
+	cols := tb.Columns()
+	assert.EqualValues(t, 1, len(cols))
+	assert.True(t, cols[0].IsAutoIncrement)
+	assert.True(t, cols[0].IsPrimaryKey)
+	assert.Equal(t, "id", cols[0].Name)
+
+	type TestAutoIncr2 struct {
+		Id int64 `xorm:"id"`
+	}
+
+	tb = testEngine.TableInfo(new(TestAutoIncr2))
+	cols = tb.Columns()
+	assert.EqualValues(t, 1, len(cols))
+	assert.False(t, cols[0].IsAutoIncrement)
+	assert.False(t, cols[0].IsPrimaryKey)
+	assert.Equal(t, "id", cols[0].Name)
+
+	type TestAutoIncr3 struct {
+		Id int64 `xorm:"'ID'"`
+	}
+
+	tb = testEngine.TableInfo(new(TestAutoIncr3))
+	cols = tb.Columns()
+	assert.EqualValues(t, 1, len(cols))
+	assert.False(t, cols[0].IsAutoIncrement)
+	assert.False(t, cols[0].IsPrimaryKey)
+	assert.Equal(t, "ID", cols[0].Name)
+
+	type TestAutoIncr4 struct {
+		Id int64 `xorm:"pk"`
+	}
+
+	tb = testEngine.TableInfo(new(TestAutoIncr4))
+	cols = tb.Columns()
+	assert.EqualValues(t, 1, len(cols))
+	assert.False(t, cols[0].IsAutoIncrement)
+	assert.True(t, cols[0].IsPrimaryKey)
+	assert.Equal(t, "id", cols[0].Name)
+}