func TestDatabaseV1ServiceCanQuery(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}
	version := skipIfServiceNotFound(t, "database")

	_, authenticator, ap := authenticate(t)
	// Either it works or fails with the failure below.
	_, err := authenticator.GetServiceURL("database", version)
	if err != nil {
		if err.Error() == "ServiceCatalog does not contain serviceType 'database'" {
			t.Skip("Database service does not exist in region, skipping")
		} else {
			testUtil.Equals(t, fmt.Sprintf(identity.ServiceEndpointWithSpecifiedRegionAndVersionNotFound, "database", ap.Region, "v13.6"), err.Error())
		}

		return
	}

	databaseService := database.NewService(authenticator)
	_, err = databaseService.Flavors()
	testUtil.IsNil(t, err)
}
// Image examples.
func TestDatabaseServiceScenarios(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}

	if os.Getenv("OS_AUTH_URL") == "" {
		t.Skip("Cannot run integration test as the Openstack env vars aren't set.")
	}

	authenticator, err := identity.AuthenticateFromEnvVars()
	authenticator.(requester.Manager).SetFunction(requester.DebugRequestMakerGenerator(nil, nil, testing.Verbose()))
	if err != nil {
		t.Fatal("Cannot authenticate from env vars:", err)
	}

	databaseService := database.NewService(authenticator)

	user := database.UserParameter{Name: "User1", Password: "******"}
	db := database.CreateDatabaseParameters{Name: "newDb"}
	createInstanceParams := database.CreateInstanceParameters{
		Databases: []database.CreateDatabaseParameters{db},
		FlavorRef: "1001",
		Name:      "Instance1",
		Users:     []database.UserParameter{user},
	}

	instance, err := databaseService.CreateInstance(createInstanceParams)
	if err != nil {
		t.Fatal("Cannot create instance:", err)
	}

	WaitUntilActiveOrError(t, databaseService, instance.ID)

	foundInstance := false
	instances, err := databaseService.Instances()
	if err != nil {
		t.Fatal("Cannot query Instances:", err)
	}

	for _, i := range instances {
		if i.ID == instance.ID {
			foundInstance = true
			break
		}
	}

	if !foundInstance {
		t.Fatal("Cannot find new instance")
	}

	err = databaseService.CreateUser(instance.ID, database.UserParameter{Name: "username", Password: "******"})
	if err != nil {
		t.Fatal("Cannot create user", err)
	}

	err = databaseService.DeleteUser(instance.ID, "username")
	if err != nil {
		t.Fatal("Cannot delete user", err)
	}

	pwd, err := databaseService.EnableRoot(instance.ID)
	if err != nil {
		t.Fatal("Cannot enable root", err)
	}
	testUtil.Assert(t, pwd.Name != "", "No Name")

	backup, err := databaseService.CreateBackup(database.CreateBackupParameters{Name: "NewBackup", InstanceID: instance.ID, Description: "Test Description"})
	if err != nil {
		t.Fatal("Cannot make backup", err)
	}
	WaitUntilActiveOrError(t, databaseService, instance.ID)

	err = databaseService.DeleteInstance(instance.ID)
	if err != nil {
		t.Fatal("Delete instance didn't work:", err)
	}

	newInstance, err := databaseService.RestoreBackupInstance(database.RestoreBackupParameters{Name: "Instance1", RestorePoint: database.RestorePoint{BackupRef: backup.ID}, FlavorRef: "1001"})
	if err != nil {
		t.Fatal("Cannot restore a backup", err)
	}

	WaitUntilActiveOrError(t, databaseService, newInstance.ID)

	err = databaseService.DeleteBackup(backup.ID)
	if err != nil {
		t.Fatal("Cannot delete backup", err)
	}

	err = databaseService.DeleteInstance(newInstance.ID)
	if err != nil {
		t.Fatal("Delete instance didn't work:", err)
	}
}