Пример #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)
}