Skip to content

Commit

Permalink
fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-qvest-seidl committed Aug 5, 2024
1 parent 82b87e1 commit c488366
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ func TestMain(m *testing.M) {

code := m.Run()

// Clean up of tests is not fatal if it fails
err := keycloakClient.DeleteRealm(testCtx, testAccRealm.Realm)
if err != nil {
log.Fatalf("Unable to delete realm %s: %s", testAccRealmUserFederation.Realm, err)
log.Printf("Unable to delete realm %s: %s", testAccRealmUserFederation.Realm, err)
}

err = keycloakClient.DeleteRealm(testCtx, testAccRealmTwo.Realm)
if err != nil {
log.Fatalf("Unable to delete realm %s: %s", testAccRealmUserFederation.Realm, err)
log.Printf("Unable to delete realm %s: %s", testAccRealmUserFederation.Realm, err)
}

err = keycloakClient.DeleteRealm(testCtx, testAccRealmUserFederation.Realm)
if err != nil {
log.Fatalf("Unable to delete realm %s: %s", testAccRealmUserFederation.Realm, err)
log.Printf("Unable to delete realm %s: %s", testAccRealmUserFederation.Realm, err)
}

os.Exit(code)
Expand All @@ -78,7 +79,15 @@ func createTestRealm(testCtx context.Context) *keycloak.Realm {
Enabled: true,
}

err := keycloakClient.NewRealm(testCtx, r)
var err error
for i := 0; i < 3; i++ { // on CI this sometimes fails and keycloak can't be reached
err = keycloakClient.NewRealm(testCtx, r)
if err != nil {
log.Printf("Unable to create new realm: %s - retrying", err)
} else {
break
}
}
if err != nil {
log.Fatalf("Unable to create new realm: %s", err)
}
Expand Down
5 changes: 5 additions & 0 deletions provider/resource_keycloak_realm_user_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestAccKeycloakRealmUserProfile_basicEmpty(t *testing.T) {
realmName := acctest.RandomWithPrefix("tf-acc")

realmUserProfile := &keycloak.RealmUserProfile{}
if ok, _ := keycloakClient.VersionIsLessThanOrEqualTo(testCtx, keycloak.Version_23); ok {
// Username and email can't be removed in this version
realmUserProfile.Attributes = []*keycloak.RealmUserProfileAttribute{{Name: "username"}, {Name: "email"}}
}

resource.Test(t, resource.TestCase{
ProviderFactories: testAccProviderFactories,
Expand All @@ -62,6 +66,7 @@ func TestAccKeycloakRealmUserProfile_basicFull(t *testing.T) {

realmUserProfile := &keycloak.RealmUserProfile{
Attributes: []*keycloak.RealmUserProfileAttribute{
{Name: "username"}, {Name: "email"}, // Version 23 needs these
{Name: "attribute1"},
{
Name: "attribute2",
Expand Down

0 comments on commit c488366

Please sign in to comment.