Пример #1
0
func TestFileElementRelativePath(t *testing.T) {
	e := createElement(filename, pwd)

	assert.True(t, e.IsExists())
	assert.False(t, e.IsDir())
	assert.False(t, e.IsSymLink())
	assert.Equal(t, filepath.Join(pwd, filename), e.Path())
	assert.Equal(t, filepath.Dir(filepath.Join(pwd, filename)), e.Dirname())
}
Пример #2
0
func TestFileElementFullPath(t *testing.T) {
	fullPath := filepath.Join(pwd, filename)
	e := createElement(fullPath, "/path/to/dummy")

	assert.True(t, e.IsExists())
	assert.False(t, e.IsDir())
	assert.False(t, e.IsSymLink())
	assert.Equal(t, fullPath, e.Path())
	assert.Equal(t, filepath.Dir(fullPath), e.Dirname())
}
Пример #3
0
func TestNotExistsElementFullPath(t *testing.T) {
	file := filepath.Join(pwd, "invalid")
	e := createElement(file, "/path/to/dummy")

	assert.False(t, e.IsExists())
	assert.False(t, e.IsDir())
	assert.False(t, e.IsSymLink())
	assert.Equal(t, file, e.Path())
	assert.Equal(t, pwd, e.Dirname())
}
Пример #4
0
func TestNotExistsElementRelativePath(t *testing.T) {
	file := "invalid"
	e := createElement(file, pwd)

	assert.False(t, e.IsExists())
	assert.False(t, e.IsDir())
	assert.False(t, e.IsSymLink())
	assert.Equal(t, filepath.Join(pwd, file), e.Path())
	assert.Equal(t, pwd, e.Dirname())
}
Пример #5
0
func TestInsertBlacklist(t *testing.T) {
	// type Person struct {
	// 	ID        int64          `db:"id"`
	// 	Name      string         `db:"name"`
	// 	Foo       string         `db:"foo"`
	// 	Email     dat.NullString `db:"email"`
	// 	Key       dat.NullString `db:"key"`
	// 	Doc       dat.NullString `db:"doc"`
	// 	CreatedAt dat.NullTime   `db:"created_at"`
	// }

	// Insert by specifying a record (struct)
	person2 := Person{Name: "Barack"}
	person2.Email.Valid = true
	person2.Email.String = "*****@*****.**"
	var email sql.NullString
	var name string
	var id int64

	err := testDB.
		InsertInto("people").
		Blacklist("id", "foo", "email", "key", "doc", "created_at").
		Record(person2).
		Returning("id", "name", "email").
		QueryScalar(&id, &name, &email)
	assert.NoError(t, err)
	assert.True(t, id > 0)
	assert.False(t, email.Valid)
	assert.Equal(t, name, "Barack")
}
Пример #6
0
func TestInvalidNullTime(t *testing.T) {
	n := NullTime{pq.NullTime{Valid: false}}

	assert.False(t, n.Valid)
	var when time.Time
	assert.Equal(t, n.Time, when)
}
Пример #7
0
func TestBrokenFileSymlinkElementRelativePath(t *testing.T) {
	e := createElement(brokenFileSymlink, pwd)

	assert.True(t, e.IsExists())
	assert.False(t, e.IsDir())
	assert.True(t, e.IsSymLink())
	assert.Equal(t, filepath.Join(pwd, brokenFileSymlink), e.Path())
	assert.Equal(t, filepath.Dir(filepath.Join(pwd, brokenFileSymlink)), e.Dirname())
}
Пример #8
0
func TestInsertWhitelist(t *testing.T) {
	// Insert by specifying a record (struct)
	person2 := Person{Name: "Barack"}
	person2.Email.Valid = true
	person2.Email.String = "*****@*****.**"
	var email sql.NullString
	var name string
	var id int64
	err := testDB.
		InsertInto("people").
		Whitelist("name").
		Record(person2).
		Returning("id", "name", "email").
		QueryScalar(&id, &name, &email)
	assert.NoError(t, err)
	assert.True(t, id > 0)
	assert.False(t, email.Valid)
	assert.Equal(t, name, "Barack")
}