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) } }
// s4 adds the function used to add a new user. func s4() error { return db.Execute(usersql.AddFunction) }
// s3 adds the function used to generate 'null' IDs. func s3() error { return db.Execute(usersql.CreateNullFunction) }
// s2 adds the ID generator function. func s2() error { return db.Execute(usersql.CreateIDFunction) }
// s1 adds the password encryption function. func s1() error { return db.Execute(usersql.CreateEncryptionFunction) }
// s0 creates the initial user table. func s0() error { return db.Execute(usersql.CreateTable) }