예제 #1
0
func TestUpgrade(t *testing.T) {

	// Happy path...
	if err := db.Connect(host, port, schema, user, password); nil != err {
		t.Errorf("Unable to connect to database: %v", err)
	}
	db.Execute("DROP SCHEMA sample")
	if err := db.Execute("CREATE SCHEMA sample DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); nil != err {
		t.Errorf("Unable to create database: %v", err)
	}
	if err := db.Connect(host, port, schema, user, password); nil != err {
		t.Errorf("Unable to reconnect to database: %v", err)
	}

	if err := Upgrade(); nil != err {
		t.Errorf("Upgrade failed: %v", err)
	}

	// Error path...
	db.Execute("DROP SCHEMA sample")
	if err := db.Execute("CREATE SCHEMA sample DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); nil != err {
		t.Errorf("Unable to create database: %v", err)
	}
	if err := db.Connect(host, port, schema, user, password); nil != err {
		t.Errorf("Unable to reconnect to database: %v", err)
	}

	if err := db.Execute(usersql.CreateEncryptionFunction); nil != err {
		t.Errorf("Unable to add pre-existing function: %v", err)
	}

	if err := Upgrade(); nil == err {
		t.Error("Upgrade succeeded when it should have failed")
	}

	// Restore database...
	db.Execute("DROP SCHEMA sample")
	if err := db.Execute("CREATE SCHEMA sample DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci"); nil != err {
		t.Errorf("Unable to create database: %v", err)
	}
}
예제 #2
0
// s4 adds the function used to add a new user.
func s4() error {
	return db.Execute(usersql.AddFunction)
}
예제 #3
0
// s3 adds the function used to generate 'null' IDs.
func s3() error {
	return db.Execute(usersql.CreateNullFunction)
}
예제 #4
0
// s2 adds the ID generator function.
func s2() error {
	return db.Execute(usersql.CreateIDFunction)
}
예제 #5
0
// s1 adds the password encryption function.
func s1() error {
	return db.Execute(usersql.CreateEncryptionFunction)
}
예제 #6
0
// s0 creates the initial user table.
func s0() error {
	return db.Execute(usersql.CreateTable)
}