當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Tspy類代碼示例

本文整理匯總了Golang中github.com/rzajac/goassert/assert.Tspy的典型用法代碼示例。如果您正苦於以下問題:Golang Tspy類的具體用法?Golang Tspy怎麽用?Golang Tspy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Tspy類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Test_ErrorCode

func Test_ErrorCode(t *testing.T) {
	err1 := new(mysql.Error)
	err1.Code = 123
	err1.Msg = []byte("Test1")

	myT := new(assert.Tspy)
	ErrorCode(myT, err1, 1234)

	if !myT.Failed() {
		t.Fatal("Expected ErrorCode to fail.")
	}

	myT = new(assert.Tspy)
	ErrorCode(myT, err1, 123)

	if myT.Failed() {
		t.Fatal("Expected ErrorCode not to fail.")
	}

	err2 := errors.New("Test1")
	myT = new(assert.Tspy)
	ErrorCode(myT, err2, 1234)

	if !myT.Failed() {
		t.Fatal("Expected ErrorCode to fail.")
	}

	myT = new(assert.Tspy)
	ErrorCode(myT, nil, 1234)

	if !myT.Failed() {
		t.Fatal("Expected ErrorCode to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:34,代碼來源:assertmysql_test.go

示例2: Test_RowDoesNotExists

func Test_RowDoesNotExists(t *testing.T) {

	// Row exists
	myT := new(assert.Tspy)
	RowDoesNotExists(myT, "test_1", "Id", 12)

	if !myT.Failed() {
		t.Fatal("Expected RowExists to fail.")
	}

	// Row does not exist
	myT = new(assert.Tspy)
	RowDoesNotExists(myT, "test_1", "Id", 1234)

	if myT.Failed() {
		t.Fatal("Expected RowExists not to fail.")
	}

	// Row does not exist
	myT = new(assert.Tspy)
	RowDoesNotExists(myT, "test_1s", "Id", "xyz")

	if myT.Failed() {
		t.Fatal("Expected RowExists not to fail.")
	}

	// Row exists
	myT = new(assert.Tspy)
	RowDoesNotExists(myT, "test_1s", "Id", "abc")

	if !myT.Failed() {
		t.Fatal("Expected RowExists to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:34,代碼來源:assertmysql_test.go

示例3: Test_RowExists

func Test_RowExists(t *testing.T) {
	// Prepare test
	err := InsertToTestTable("test_1", 12, 123)
	if err != nil {
		t.Fatal("Did not expect database error: " + err.Error())
	}

	// Row does not exist
	myT := new(assert.Tspy)
	RowExists(myT, "test_1", "Id", 111)

	if !myT.Failed() {
		t.Fatal("Expected RowExists to fail.")
	}

	// Row exists
	myT = new(assert.Tspy)
	RowExists(myT, "test_1", "Id", 12)

	if myT.Failed() {
		t.Fatal("Expected RowExists not to fail.")
	}

	// Test string keys - prepare table and data
	createSql := `
	CREATE TABLE %s (
	  Id char(5) NOT NULL,
	  Field int(11) DEFAULT NULL,
	  PRIMARY KEY (id)
	) ENGINE=%s`

	_, _, err = dbcon.Query(createSql, "test_1s", TEST_DB_ENGINE)
	if err != nil {
		t.Fatal("Did not expect database error: " + err.Error())
	}

	insertSql := fmt.Sprintf("INSERT INTO test_1s VALUES ('abc', 1)")
	_, _, err = dbcon.Query(insertSql)
	if err != nil {
		t.Fatal("Did not expect database error: " + err.Error())
	}

	// Row does not exist
	myT = new(assert.Tspy)
	RowExists(myT, "test_1s", "Id", "xyz")

	if !myT.Failed() {
		t.Fatal("Expected RowExists to fail.")
	}

	// Row exists
	myT = new(assert.Tspy)
	RowExists(myT, "test_1s", "Id", "abc")

	if myT.Failed() {
		t.Fatal("Expected RowExists not to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:58,代碼來源:assertmysql_test.go

示例4: Test_TableCount

func Test_TableCount(t *testing.T) {
	myT := new(assert.Tspy)
	TableCount(myT, 100)

	if !myT.Failed() {
		t.Fatal("Expected TableCount to fail.")
	}

	myT = new(assert.Tspy)
	TableCount(myT, 6)

	if myT.Failed() {
		t.Fatal("Expected TableCount not to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:15,代碼來源:assertmysql_test.go

示例5: Test_TableDoesNotExists

func Test_TableDoesNotExists(t *testing.T) {
	myT := new(assert.Tspy)

	TableDoesNotExists(myT, "not_existing_table")

	if myT.Failed() {
		t.Fatal("Expected TableDoesNotExists not to fail.")
	}

	myT = new(assert.Tspy)
	TableDoesNotExists(myT, "test_1")

	if !myT.Failed() {
		t.Fatal("Expected TableDoesNotExists to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:16,代碼來源:assertmysql_test.go

示例6: Test_LoadFixture

func Test_LoadFixture(t *testing.T) {

	TruncateTable("test_1")
	myT := new(assert.Tspy)
	LoadFixture(myT, "/not/existing/fixture")

	if !myT.Failed() {
		t.Fatalf("Expected error loading not existing fixture")
	}

	myT = new(assert.Tspy)
	LoadFixture(myT, "fixtures/fixture.sql")

	if myT.Failed() {
		t.Fatalf("Did not expect any error: %s", myT.GetMsg(0))
	}

	rows, res, err := dbcon.Query("SELECT * FROM test_1 ORDER BY Field ASC")
	if err != nil {
		t.Fatal("Did not expect error: " + err.Error())
	}

	if len(rows) != 3 {
		t.Fatal("Expected three rows in the database.")
	}

	for idx, row := range rows {
		if idx != row.Int(res.Map("Field")) {
			t.Fatalf("Expected row %d Field to be equal to %d", idx, row.Int(res.Map("Field")))
		}
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:32,代碼來源:assertmysql_test.go

示例7: Test_TableRowCount

func Test_TableRowCount(t *testing.T) {

	myT := new(assert.Tspy)
	TableRowCount(myT, "test_1", 100)

	if !myT.Failed() {
		t.Fatal("Expected TableRowCount to fail.")
	}

	myT = new(assert.Tspy)
	TableRowCount(myT, "test_1", 1)

	if myT.Failed() {
		t.Fatal("Expected TableRowCount not to fail.")
	}

	InsertToTestTable("test_1", 2, 456)

	myT = new(assert.Tspy)
	TableRowCount(myT, "test_1", 2)

	if myT.Failed() {
		t.Fatal("Expected TableRowCount not to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:25,代碼來源:assertmysql_test.go

示例8: Test_NotError

func Test_NotError(t *testing.T) {
	err1 := errors.New("Test1")
	err2 := new(mysql.Error)

	myT := new(assert.Tspy)
	NotError(myT, err2, "Custom message")

	if !myT.Failed() {
		t.Fatal("Expected NotError to fail.")
	}

	myT = new(assert.Tspy)
	NotError(myT, err1)

	if myT.Failed() {
		t.Fatal("Expected NotError not to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:18,代碼來源:assertmysql_test.go

示例9: Test_TableNotEmpty

func Test_TableNotEmpty(t *testing.T) {

	// Table empty
	myT := new(assert.Tspy)
	TableNotEmpty(myT, "test0")

	if !myT.Failed() {
		t.Fatal("Expected TableNotEmpty to fail.")
	}

	// Table not empty
	myT = new(assert.Tspy)
	TableNotEmpty(myT, "test_1")

	if myT.Failed() {
		t.Fatal("Expected TableNotEmpty to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:18,代碼來源:assertmysql_test.go

示例10: Test_TableExists

func Test_TableExists(t *testing.T) {
	myT := new(assert.Tspy)

	TableExists(myT, "not_existing_table")

	if !myT.Failed() {
		t.Fatal("Expected TableExists to fail.")
	}

	err := CreateTestTable("test_1", TEST_DB_ENGINE)
	if err != nil {
		t.Fatal("Did not expect database error: " + err.Error())
	}

	myT = new(assert.Tspy)
	TableExists(myT, "test_1")

	if myT.Failed() {
		t.Fatal("Expected TableExists not to fail.")
	}
}
開發者ID:rzajac,項目名稱:goassert,代碼行數:21,代碼來源:assertmysql_test.go


注:本文中的github.com/rzajac/goassert/assert.Tspy類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。