コード例 #1
0
ファイル: cmd_test.go プロジェクト: funny/cmd
func Test_Cmd(t *testing.T) {
	Register("lookup api", "save api time record to file", func(args []string) interface{} {
		utest.EqualNow(t, args[0], "lookup api")
		return 1
	})

	Register("lookup gc", "save gc summary to file", func(args []string) interface{} {
		utest.EqualNow(t, args[0], "lookup gc")
		return 2
	})

	Register("lookup heap ([0-2])", "save heap status to file", func(args []string) interface{} {
		utest.EqualNow(t, args[1], "1")
		return 3
	})

	n, ok := Process("lookup api")
	utest.Assert(t, ok && n == 1, n)
	Process("lookup gc")

	n, ok = Process("lookup gc")
	utest.Assert(t, ok && n == 2, n)

	n, ok = Process("lookup heap 1")
	utest.Assert(t, ok && n == 3, n)
}
コード例 #2
0
ファイル: main_test.go プロジェクト: miffa/gateway
func Test_Fatals(t *testing.T) {
	// missing passphrase
	oldSecret := cfgSecret
	defer func() {
		cfgSecret = oldSecret
	}()
	cfgSecret = nil
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Missing passphrase"))
		}()
		main()
	}()
	cfgSecret = oldSecret

	// bad pprof address
	cfgPprofAddr = "xxoo"
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Setup pprof failed"))
		}()
		main()
	}()
	cfgPprofAddr = "0.0.0.0:0"

	// bad gateway address
	oldAddr := cfgGatewayAddr
	defer func() {
		cfgGatewayAddr = oldAddr
	}()
	cfgGatewayAddr = "abc"
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Setup listener failed"))
		}()
		main()
	}()

	// bad gateway address with reuse port
	cfgReusePort = true
	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Setup listener failed"))
		}()
		start()
	}()
}
コード例 #3
0
ファイル: atom_test.go プロジェクト: funny/slab
func Test_AtomPool_AllocAndFree(t *testing.T) {
	pool := NewAtomPool(128, 64*1024, 2, 1024*1024)
	for i := 0; i < len(pool.classes); i++ {
		temp := make([][]byte, len(pool.classes[i].chunks))

		for j := 0; j < len(temp); j++ {
			mem := pool.Alloc(pool.classes[i].size)
			utest.EqualNow(t, cap(mem), pool.classes[i].size)
			temp[j] = mem
		}
		utest.Assert(t, pool.classes[i].head == 0)

		for j := 0; j < len(temp); j++ {
			pool.Free(temp[j])
		}
		utest.Assert(t, pool.classes[i].head != 0)
	}
}
コード例 #4
0
ファイル: atom_test.go プロジェクト: funny/slab
func Test_AtomPool_AllocSlow(t *testing.T) {
	pool := NewAtomPool(128, 1024, 2, 1024)
	mem := pool.classes[len(pool.classes)-1].Pop()
	utest.EqualNow(t, cap(mem), 1024)
	utest.Assert(t, pool.classes[len(pool.classes)-1].head == 0)

	mem = pool.Alloc(1024)
	utest.EqualNow(t, cap(mem), 1024)
}
コード例 #5
0
ファイル: all_test.go プロジェクト: houcy/mysql
func Test_Connect(t *testing.T) {
	param := TestConnParam
	param.DbName = "mysql"

	conn, err := Connect(param)
	utest.IsNilNow(t, err)

	conn.Close()
	utest.Assert(t, conn.IsClosed())
}
コード例 #6
0
ファイル: all_test.go プロジェクト: houcy/mysql
func Test_Null(t *testing.T) {
	conn, err := Connect(TestConnParam)
	utest.IsNilNow(t, err)
	defer conn.Close()

	var res DataTable

	res, err = conn.QueryTable("SELECT SUM(value) FROM test")
	utest.IsNilNow(t, err)

	rows1 := res.Rows()
	utest.EqualNow(t, len(rows1), 1)
	utest.Assert(t, !rows1[0][0].IsNull())

	res, err = conn.QueryTable("SELECT SUM(value) FROM test WHERE id > 8888")
	utest.IsNilNow(t, err)

	rows2 := res.Rows()
	utest.EqualNow(t, len(rows2), 1)
	utest.Assert(t, rows2[0][0].IsNull())
}
コード例 #7
0
ファイル: main_test.go プロジェクト: miffa/gateway
func Test_Accept(t *testing.T) {
	_, err := accept(&TestListener{
		9, TestError{false, true},
	})
	utest.IsNilNow(t, err)

	_, err = accept(&TestListener{
		-1, TestError{true, false},
	})
	utest.NotNilNow(t, err)

	func() {
		defer func() {
			err := recover()
			utest.NotNilNow(t, err)
			utest.Assert(t, strings.Contains(err.(string), "Gateway accept failed"))
		}()
		loop(&TestListener{
			-1, TestError{true, false},
		})
	}()
}