Esempio n. 1
0
func TestInvalidTask(t *testing.T) {
	tasks := func(p *Project) {
	}

	assert.Panics(t, func() {
		runTask(tasks, "dummy")
	})
}
Esempio n. 2
0
func TestInsertWhitelist(t *testing.T) {
	objs := []someRecord{{1, 88, false}, {2, 99, true}}
	sql, args := InsertInto("a").
		Whitelist("*").
		Record(objs[0]).
		Record(objs[1]).
		ToSQL()
	assert.Equal(t, sql, quoteSQL("INSERT INTO a (%s,%s,%s) VALUES ($1,$2,$3),($4,$5,$6)", "something_id", "user_id", "other"))
	checkSliceEqual(t, []interface{}{1, 88, false, 2, 99, true}, args)

	assert.Panics(t, func() {
		InsertInto("a").Whitelist("*").Values("foo").ToSQL()
	}, `must use "*" in conjunction with Record`)
}
Esempio n. 3
0
func TestEmbeddedStructInvalidColumns(t *testing.T) {
	type Realm struct {
		RealmUUID string
	}
	type Group struct {
		GroupUUID string `db:"group_uuid"`
		*Realm
	}

	g := &Group{Realm: &Realm{"11"}, GroupUUID: "22"}

	assert.Panics(t, func() {
		InsertInto("groups").Columns("group_uuid", "realm_uuid").Record(g).ToSQL()
	})
}
Esempio n. 4
0
func TestInsertBlacklist(t *testing.T) {
	objs := []someRecord{{1, 88, false}, {2, 99, true}}
	sql, args := InsertInto("a").
		Blacklist("something_id").
		Record(objs[0]).
		Record(objs[1]).
		ToSQL()
	assert.Equal(t, sql, `INSERT INTO a ("user_id","other") VALUES ($1,$2),($3,$4)`)
	checkSliceEqual(t, args, []interface{}{88, false, 99, true})

	assert.Panics(t, func() {
		// does not have any columns or record
		InsertInto("a").Blacklist("something_id").Values("foo").ToSQL()
	})

}
Esempio n. 5
0
func TestTaskArgs(t *testing.T) {
	assert := assert.New(t)
	result := ""
	tasks := func(p *Project) {
		p.Task1("foo", func(c *Context) {
			name := c.Args.MustString("name")
			result = name
		})
	}

	execCLI(tasks, []string{"foo", "--", "--name=gopher"}, nil)
	assert.Equal("gopher", result)
	assert.Panics(func() {
		runTask(tasks, "foo")
	})
}
Esempio n. 6
0
func TestConstructMessageBody(t *testing.T) {
	assert := assert.New(t)

	headerlist := []string{"From", "To", "Subject"}

	headers := make(map[string]string)
	headers["From"] = "Fictious sender <*****@*****.**>"
	headers["To"] = "\"Fictious recipient\" <*****@*****.**>"
	headers["Subject"] = "Example subject"

	expected_body := "From: Fictious sender <*****@*****.**>\n" +
		"To: \"Fictious recipient\" <*****@*****.**>\n" +
		"Subject: Example subject"

	assert.Equal(expected_body, constructMessageBody(headers, headerlist))

	assert.Panics(func() {
		constructMessageBody(headers, []string{"Missing key"})
	})
}
Esempio n. 7
0
func TestUpsertSQLMissingWhere(t *testing.T) {
	assert.Panics(t, func() {
		Upsert("tab").Columns("b", "c").Values(1, 2).ToSQL()
	})
}