Beispiel #1
0
func TestMirroring(t *testing.T) {
	if !IsMirrorHostDefined() {
		t.Skip("mirror host is not defined")
	}
	conn := ConnectToTestDb(t)
	if conn == nil {
		return
	}
	defer conn.Close()

	rst, err := conn.Exec("select * from authors")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 23, len(rst[0].Rows))
	assert.Equal(t, 23, rst[0].RowsAffected)

	err = failover(conn)
	if err != nil {
		fmt.Printf("failover error %s %s %s\n", err, conn.Error, conn.Message)
		assert.Nil(t, err)
	}
	rst, err = conn.Exec("select * from authors")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 23, len(rst[0].Rows))
	assert.Equal(t, 23, rst[0].RowsAffected)
}
Beispiel #2
0
func TestExecute(t *testing.T) {
	conn := ConnectToTestDb(t)
	if conn == nil {
		return
	}
	defer conn.Close()

	rst, err := conn.Exec("select 1")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst))
	rst, err = conn.Exec("select missing")
	assert.NotNil(t, err)
	assert.Nil(t, rst)
	rst, err = conn.Exec("print 'pero'")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.True(t, strings.Contains(conn.Message, "pero"))
	assert.Equal(t, 1, len(rst))
	assert.Equal(t, 0, len(rst[0].Rows))
	rst, err = conn.Exec("sp_help 'authors'")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 9, len(rst))
}
Beispiel #3
0
func TestData(t *testing.T) {

	c := new(WebContext)

	c.data = nil

	assert.NotNil(t, c.Data())
	assert.NotNil(t, c.data)

}
Beispiel #4
0
func TestDoubleMountFails(t *testing.T) {
	var m = NewMemory()
	m.Mounts = []Mount{}

	first := new(MockDevice)
	second := new(MockDevice)

	assert.Nil(t, m.Mount(first, 0x0500, 0x0fff))
	assert.NotNil(t, m.Mount(second, 0x0400, 0x600))
	assert.NotNil(t, m.Mount(second, 0x0f00, 0x1000))
	assert.NotNil(t, m.Mount(second, 0x0501, 0x0f00))
}
func TestStoredProcedureNotExists(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_sp_not_exists", `as return`)
	assert.Nil(t, err)
	rst, err := conn.ExecSp("test_sp_not_exists")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	_, err = conn.Exec("drop procedure test_sp_not_exists")
	assert.Nil(t, err)
	rst, err = conn.ExecSp("test_sp_not_exists")
	assert.NotNil(t, err)
	assert.Nil(t, rst)
}
func TestTimeSpParams(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_sp_time_sp_params", `@p1 datetime as
    insert into tm (tm) values(@p1)
    select @p1, 123
    return 0`)
	assert.Nil(t, err)

	f := func(tmIn time.Time) {
		var tmOut time.Time
		var i int
		rst, err := conn.ExecSp("test_sp_time_sp_params", tmIn)
		assert.Nil(t, err)
		assert.NotNil(t, rst)
		rst.Next()
		rst.Scan(&tmOut, &i)
		assert.Equal(t, tmIn.UTC(), tmOut.UTC())
		if !tmIn.Equal(tmOut) {
			t.Errorf("%s != %s", tmIn, tmOut)
		}
	}

	f(time.Unix(1404856799, 0))
	f(time.Unix(1404856800, 0))
	f(time.Unix(1404856801, 0))

	f(time.Unix(1404856799, 0).UTC())
	f(time.Unix(1404856800, 0).UTC())
	f(time.Unix(1404856801, 0).UTC())
}
func Test_ParseURL_BadValue(t *testing.T) {
	expected := ""
	test_string := `www.venuecom.com?beef=stew&whee=phew%C3%BC`
	parsed, err := ParseURL(test_string)
	assert.NotNil(t, err, fmt.Sprintf("unexpected nil error from ParseURL on parsed item \"%s\"", test_string))
	assert.Equal(t, parsed, expected, fmt.Sprintf("parsed item \"%s\" did not match expected \"%s\"", parsed, expected))
}
Beispiel #8
0
// full build (all targets), one action fails
func Test_BuildState_BuildTargets_one_failure(t *testing.T) {
	sig := []byte{0}
	graph, executed := setupBuild(false, sig)
	db := makeFakeDB(graph, sig)

	// fail to build misc.{c,h} -> misc.o: that will stop the build
	rule := graph.Lookup("misc.o").BuildRule().(*dag.StubRule)
	rule.SetFail(true)

	expect := []buildexpect{
		{"tool1.o", dag.BUILT},
		{"misc.o", dag.FAILED},
	}

	opts := BuildOptions{}
	bstate := NewBuildState(graph, db, opts)
	goal := graph.MakeNodeSet("tool1", "tool2")
	err := bstate.BuildTargets(goal)
	assert.NotNil(t, err)
	assertBuild(t, graph, expect, *executed)

	// we didn't even think about building util.o, tool1, etc: an
	// earlier node failed and the build terminates on first failure
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("util.o").State())
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("tool1").State())
	assert.Equal(t, dag.UNKNOWN, graph.Lookup("tool2").State())
}
func Test_SitemapPageSizeLimitations(t *testing.T) {
	buf := make([]byte, max_sitemap_page_size+1)

	reader := bytes.NewBuffer(buf)
	_, err := NewSitemapPage(reader)
	assert.NotNil(t, err, fmt.Sprintf("expected error from NewSitemapPage"))
}
Beispiel #10
0
func TestNewDateTypesParam(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_sp_with_datetimeoffset_param", `
    (@p1 datetimeoffset, @p2 date, @p3 time, @p4 datetime2) as
    DECLARE @datetime datetime = @p1;
    SELECT @datetime, @p1, @p2, @p3, @p4
    return `)
	assert.Nil(t, err)
	p1 := "2025-12-10 12:32:10.1237000 +01:00"
	p2 := "2025-12-10"
	p3 := "12:30"
	p4 := "2025-12-10 12:32:10"
	rst, err := conn.ExecSp("test_sp_with_datetimeoffset_param", p1, p2, p3, p4)
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	rst.Next()
	var op1, op2, op3, op4 string
	var dt time.Time
	err = rst.Scan(&dt, &op1, &op2, &op3, &op4)
	assert.Nil(t, err)
	assert.Equal(t, "2025-12-10T12:32:10+01:00", dt.Format(time.RFC3339))
	assert.Equal(t, "2025-12-10 12:32:10.1237000 +01:00", op1)
	assert.Equal(t, "2025-12-10", op2)
	assert.Equal(t, "12:30:00.0000000", op3)
	assert.Equal(t, "2025-12-10 12:32:10.0000000", op4)
}
Beispiel #11
0
func TestExecSpInputParams2(t *testing.T) {
	conn := ConnectToTestDb(t)
	err := createProcedure(conn, "test_input_params2", "@p1 nvarchar(255), @p2 varchar(255), @p3 nvarchar(255), @p4 nchar(10), @p5 varbinary(10) as select @p1, @p2, @p3, @p4, @p5;  return")
	assert.Nil(t, err)
	want := "£¢§‹›†€"
	wantp2 := "abc"
	wantp3 := "šđčćžabc"
	wantp4 := "šđčćžabcde"
	wantp3 = "FK Ventspils v Nõmme Kalju FC"
	wantp5 := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	rst, err := conn.ExecSp("test_input_params2", want, wantp2, wantp3, wantp4, wantp5)
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	if rst == nil {
		return
	}
	assert.True(t, rst.HasResults())
	var got, gotp2, gotp3, gotp4 string
	var gotp5 []byte
	result := rst.results[0]
	result.Next()
	result.Scan(&got, &gotp2, &gotp3, &gotp4, &gotp5)
	assert.Equal(t, want, got)
	assert.Equal(t, wantp2, gotp2)
	assert.Equal(t, wantp3, gotp3)
	assert.Equal(t, wantp4, gotp4)
	assert.Equal(t, wantp5, gotp5)
	//PrintResults(rst.Results)
}
Beispiel #12
0
// full build (all targets), one action fails, --keep-going true
func Test_BuildState_BuildTargets_one_failure_keep_going(t *testing.T) {
	// this is the same as the previous test except that
	// opts.KeepGoing == true: we don't terminate the build on first
	// failure, but carry on and consider building tool1, then mark it
	// TAINTED because one of its ancestors (misc.o) failed to build

	sig := []byte{0}
	graph, executed := setupBuild(false, sig)
	db := makeFakeDB(graph, sig)

	rule := graph.Lookup("misc.o").BuildRule().(*dag.StubRule)
	rule.SetFail(true)

	expect := []buildexpect{
		{"tool1.o", dag.BUILT},
		{"misc.o", dag.FAILED},
		{"util.o", dag.BUILT},
		{"tool2.o", dag.BUILT},
		{"tool2", dag.BUILT},
	}

	opts := BuildOptions{KeepGoing: true}
	bstate := NewBuildState(graph, db, opts)
	goal := graph.MakeNodeSet("tool1", "tool2")
	err := bstate.BuildTargets(goal)
	assert.NotNil(t, err)
	assertBuild(t, graph, expect, *executed)

	assert.Equal(t, dag.TAINTED, graph.Lookup("tool1").State())
}
Beispiel #13
0
func Test_Runtime_runMainPhase_valid(t *testing.T) {
	script := "" +
		"main {\n" +
		"  src = \"foo.c\"\n" +
		"  \"foo\": src {\n" +
		"    \"cc -o $TARGET $src\"\n" +
		"  }\n" +
		"}\n"
	rt := parseScript(t, "test.fubsy", script)
	errors := rt.runMainPhase()
	assert.Equal(t, 0, len(errors))
	val, ok := rt.stack.Lookup("src")
	assert.True(t, ok)
	assert.Equal(t, types.MakeFuString("foo.c"), val)
	assert.NotNil(t, rt.dag)

	// this seems *awfully* detailed and brittle, but DAG doesn't
	// provide a good way to query what's in it (yet...)
	expect := `0000: FileNode "foo" (state UNKNOWN)
  action: "cc -o $TARGET $src"
  parents:
    0001: foo.c
0001: FileNode "foo.c" (state UNKNOWN)
`
	var buf bytes.Buffer
	rt.dag.Dump(&buf, "")
	actual := buf.String()
	if expect != actual {
		t.Errorf("dag.Dump(): expected\n%v\nbut got\n%v", expect, actual)
	}
}
func Test_parseChangeFrequency_BadValue(t *testing.T) {
	expected := ""
	test_string := `asdf`
	parsed, err := parseChangeFrequency(test_string)
	assert.NotNil(t, err, fmt.Sprintf("unexpected nil error from parseChangeFrequency on parsed item \"%s\"", test_string))
	assert.Equal(t, parsed, expected, fmt.Sprintf("parsed item \"%s\" did not match expected \"%s\"", parsed, expected))
}
Beispiel #15
0
func TestExecSp(t *testing.T) {
	conn := ConnectToTestDb(t)
	rst, err := conn.ExecSp("sp_who")
	assert.Nil(t, err)
	assert.NotNil(t, rst)
	assert.Equal(t, 1, len(rst.results))
}
Beispiel #16
0
func TestConnect(t *testing.T) {
	conn := ConnectToTestDb(t)
	assert.NotNil(t, conn)
	defer conn.Close()
	assert.True(t, conn.isLive())
	assert.False(t, conn.isDead())
}
func Test_parseLastModified_BadValue(t *testing.T) {
	expected := time.Time{}
	test_string := `asdf`
	parsed, err := parseLastModified(test_string)
	assert.NotNil(t, err, fmt.Sprintf("unexpected nil error from parseLastModified on parsed item \"%s\"", test_string))
	assert.Equal(t, parsed.String(), expected.String(), fmt.Sprintf("parsed item \"%s\" did not match expected \"%s\"", parsed, expected))
}
Beispiel #18
0
func assertPathMatchHandler(t *testing.T, handler *PathMatchHandler, path, method string, message string) bool {

	if assert.NotNil(t, handler) {

		ctx := context_test.MakeTestContextWithDetails(path, method)

		willHandle, _ := handler.WillHandle(ctx)
		if assert.True(t, willHandle, fmt.Sprintf("This handler is expected to handle it: %s", message)) {

			// make sure the method is in the list
			methodFound := false
			for _, methodInList := range handler.HttpMethods {
				if methodInList == method {
					methodFound = true
					break
				}
			}

			return assert.True(t, methodFound, "Method (%s) should be in the method list (%s)", method, handler.HttpMethods)
		}

	}

	return false

}
Beispiel #19
0
func Test_KyotoDB_key_prefix(t *testing.T) {
	// make sure we write the key exactly as expected, byte-for-byte
	cleanup := testutils.Chtemp()
	defer cleanup()

	db, err := OpenKyotoDB("test1.kch", true)
	if err != nil {
		t.Fatal(err)
	}
	assert.NotNil(t, db.kcdb)

	rec1 := NewBuildRecord()
	rec1.SetTargetSignature([]byte{})
	db.WriteNode("f", rec1)
	db.WriteNode("foobar", rec1)
	db.WriteNode("foo", rec1)

	// hmmm: does Kyoto Cabinet guarantee key order? it seems to
	// preserve insertion order from what I can tell, but I'm not
	// sure if that's reliable
	expect := []string{
		"\x00\x00\x00\x00version",
		"\x00\x00\x00\x01f",
		"\x00\x00\x00\x01foobar",
		"\x00\x00\x00\x01foo",
	}
	keychan := db.kcdb.Keys()
	for i, expectstr := range expect {
		expectkey := ([]byte)(expectstr)
		actualkey := <-keychan
		if !bytes.Equal(expectkey, actualkey) {
			t.Errorf("key %d: expected\n%v\nbut got\n%v", i, expectkey, actualkey)
		}
	}
}
func Test_Unzip_WrongFormat(t *testing.T) {
	reader := bytes.NewBuffer(plainText)

	mem_seek, gzip_err := UnGzipTransform(reader, math.MaxInt64)
	assert.NotNil(t, gzip_err, fmt.Sprintf("expected error from UnGzipTransform"))
	assert.True(t, gzip_err.GzipFailed(), fmt.Sprintf("expected true from GzipFailed"))
	bytes, _ := ioutil.ReadAll(mem_seek)
	assert.Equal(t, string(plainText), string(bytes))
}
Beispiel #21
0
func TestCreateTable(t *testing.T) {
	conn := ConnectToTestDb(t)
	assert.NotNil(t, conn)
	defer conn.Close()
	for _, s := range CREATE_DB_SCRIPTS {
		_, err := conn.Exec(s)
		assert.Nil(t, err)
	}
}
Beispiel #22
0
func Test_defineBuiltins(t *testing.T) {
	ns := defineBuiltins()

	fn, ok := ns.Lookup("println")
	assert.True(t, ok)
	assert.NotNil(t, fn)
	assert.Equal(t, fn.(types.FuCallable).Code(), types.FuCode(fn_println))

	fn, ok = ns.Lookup("remove")
	assert.True(t, ok)
	assert.NotNil(t, fn)
	assert.Equal(t, fn.(types.FuCallable).Code(), types.FuCode(fn_remove))

	// there will never be a builtin with this name: guaranteed!
	fn, ok = ns.Lookup("sad425.-afgasdf")
	assert.False(t, ok)
	assert.Nil(t, fn)
}
Beispiel #23
0
func TestResultScanWithoutNext(t *testing.T) {
	r := testResult()
	var i int
	var s string
	var tm time.Time
	var f float64
	err := r.Scan(&i, &s, &tm, &f)
	assert.NotNil(t, err)
}
Beispiel #24
0
func TestSelectValue(t *testing.T) {
	conn := ConnectToTestDb(t)
	if conn == nil {
		return
	}
	defer conn.Close()

	val, err := conn.SelectValue("select 1")
	assert.Nil(t, err)
	assert.Equal(t, 1, val)

	val, err = conn.SelectValue("select 1 where 1=2")
	assert.NotNil(t, err)
	assert.Nil(t, val)

	val, err = conn.SelectValue("select missing")
	assert.NotNil(t, err)
	assert.Nil(t, val)
}
Beispiel #25
0
func TestWrongPassword(t *testing.T) {
	connStr := testDbConnStr(1)
	c := NewCredentials(connStr)
	c.pwd = c.pwd + "_wrong"
	conn, err := connectWithCredentials(c)
	assert.NotNil(t, err)
	assert.Nil(t, conn)
	assert.True(t, strings.Contains(err.Error(), "Login failed for user"))
	//t.Logf("wrong password message: %s", err)
}
Beispiel #26
0
func assertParses(t *testing.T, expect *ASTRoot, tokens []minitok) {
	reset()
	parser := NewParser(toklist(tokens))
	result := fuParse(parser)

	assert.Nil(t, parser.syntaxerror)
	assert.Equal(t, 0, result)
	assert.NotNil(t, parser.ast)
	assertASTEqual(t, expect, parser.ast)
}
func testCredentials(t *testing.T, crd *credentials) {
	assert.NotNil(t, crd)
	assert.Equal(t, "myServerAddress", crd.host)
	assert.Equal(t, "myDataBase", crd.database)
	assert.Equal(t, "myUsername", crd.user)
	assert.Equal(t, "myPassword", crd.pwd)
	assert.Equal(t, "myMirror", crd.mirrorHost)
	assert.Equal(t, 200, crd.maxPoolSize)
	assert.Equal(t, 1000, crd.lockTimeout)
}
Beispiel #28
0
func TestNewPathPattern(t *testing.T) {

	path := "/people/{id}/books"
	p, _ := NewPathPattern(path)

	if assert.NotNil(t, p) {
		assert.Equal(t, path, p.RawPath)
	}

}
Beispiel #29
0
func TestResultScanOnNonPointerValues(t *testing.T) {
	r := testResult()
	var i int
	var s string
	var tm time.Time
	var f float64
	assert.True(t, r.Next())
	err := r.Scan(&i, &s, &tm, f)
	assert.NotNil(t, err) //error is raised
}
func TestPool(t *testing.T) {
	p, err := NewConnPool(testDbConnStr(2))
	defer p.Close()
	assert.Nil(t, err)
	assert.NotNil(t, p)
	assert.Equal(t, len(p.pool), 1)
	c1, err := p.Get()
	assert.Nil(t, err)
	assert.NotNil(t, c1)
	assert.Equal(t, len(p.pool), 0)
	c2, err := p.Get()
	assert.Nil(t, err)
	assert.NotNil(t, c2)
	assert.Equal(t, len(p.pool), 0)
	p.Release(c1)
	assert.Equal(t, len(p.pool), 1)
	p.Release(c2)
	assert.Equal(t, len(p.pool), 2)
}