Skip to content

Commit b197687

Browse files
Mikhail PutilovMikhail Putilov
authored andcommitted
Adjust tests
Signed-off-by: Mikhail Putilov <[email protected]>
1 parent dc2456a commit b197687

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

provider/resource_keycloak_openid_client_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,12 @@ func TestAccKeycloakOpenidClient_import(t *testing.T) {
761761
CheckDestroy: testAccCheckKeycloakOpenidClientNotDestroyed(),
762762
Steps: []resource.TestStep{
763763
{
764-
Config: testKeycloakOpenidClient_import("non-existing-client", true),
765-
ExpectError: regexp.MustCompile("Error: openid client with name non-existing-client does not exist"),
766-
},
767-
{
768-
Config: testKeycloakOpenidClient_import("account", true),
769-
Check: testAccCheckKeycloakOpenidClientExistsWithEnabledStatus("keycloak_openid_client.client", true),
764+
ResourceName: "keycloak_openid_client.client",
765+
ImportState: true,
766+
ImportStateId: testAccRealm.Realm + "/account",
767+
768+
Config: testKeycloakOpenidClient_import("account", false),
769+
Check: testAccCheckKeycloakOpenidClientExistsWithEnabledStatus("keycloak_openid_client.client", false),
770770
},
771771
},
772772
})
@@ -2095,7 +2095,6 @@ func testKeycloakOpenidClient_import(clientId string, enabled bool) string {
20952095
data "keycloak_realm" "realm" {
20962096
realm = "%s"
20972097
}
2098-
20992098
resource "keycloak_openid_client" "client" {
21002099
client_id = "%s"
21012100
realm_id = data.keycloak_realm.realm.id

provider/resource_keycloak_role_test.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package provider
22

33
import (
44
"fmt"
5+
"regexp"
6+
"strings"
7+
"testing"
8+
59
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
610
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
711
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
812
"github.com/keycloak/terraform-provider-keycloak/keycloak"
9-
"regexp"
10-
"strings"
11-
"testing"
1213
)
1314

1415
func TestAccKeycloakRole_basicRealm(t *testing.T) {
@@ -354,7 +355,7 @@ func TestAccKeycloakRole_import(t *testing.T) {
354355
},
355356
{
356357
Config: testKeycloakRole_importClientRole("view-profile", "non-existing-client"),
357-
ExpectError: regexp.MustCompile("openid client with name non-existing-client does not exist"),
358+
ExpectError: regexp.MustCompile("openid clientId non-existing-client does not exist in realm"),
358359
},
359360
{
360361
Config: testKeycloakRole_importClientRole("non-existing-role", "account"),
@@ -843,6 +844,10 @@ func testKeycloakRole_importClientRole(name, clientId string) string {
843844
data "keycloak_realm" "realm" {
844845
realm = "%s"
845846
}
847+
import {
848+
id = "${data.keycloak_realm.realm.id}/%s"
849+
to = keycloak_openid_client.imported-client
850+
}
846851
resource "keycloak_openid_client" "imported-client" {
847852
realm_id = data.keycloak_realm.realm.id
848853
client_id = "%s"
@@ -854,14 +859,18 @@ resource "keycloak_role" "imported-client-role" {
854859
name = "%s"
855860
import = true
856861
}
857-
`, testAccRealm.Realm, clientId, name)
862+
`, testAccRealm.Realm, clientId, clientId, name)
858863
}
859864

860865
func testKeycloakRole_importAndModifyClientRole(name, clientId, newDescription string) string {
861866
return fmt.Sprintf(`
862867
data "keycloak_realm" "realm" {
863868
realm = "%s"
864869
}
870+
import {
871+
id = "${data.keycloak_realm.realm.id}/%s"
872+
to = keycloak_openid_client.imported-client
873+
}
865874
resource "keycloak_openid_client" "imported-client" {
866875
realm_id = data.keycloak_realm.realm.id
867876
client_id = "%s"
@@ -874,7 +883,7 @@ resource "keycloak_role" "imported-client-role" {
874883
import = true
875884
description = "%s"
876885
}
877-
`, testAccRealm.Realm, clientId, name, newDescription)
886+
`, testAccRealm.Realm, clientId, clientId, name, newDescription)
878887
}
879888

880889
type NestedRole struct {
@@ -901,20 +910,23 @@ resource "keycloak_role" "%s" {
901910
importedClientIdRef := fmt.Sprintf("imported-client-%d", i)
902911

903912
importedRoles += fmt.Sprintf(`
904-
resource "keycloak_openid_client" "%s" {
913+
import {
914+
id = "${data.keycloak_realm.realm.id}/%s" # 1 ClientId
915+
to = keycloak_openid_client.%s # 2 importedClientIdRef
916+
}
917+
resource "keycloak_openid_client" "%s" { # 3 importedClientIdRef
905918
realm_id = data.keycloak_realm.realm.id
906-
client_id = "%s"
907-
import = true
919+
client_id = "%s" # 4 ClientId
908920
access_type = "PUBLIC"
909921
}
910922
911-
resource "keycloak_role" "%s" {
923+
resource "keycloak_role" "%s" { # 5 importedRoleRef
912924
realm_id = data.keycloak_realm.realm.id
913-
client_id = keycloak_openid_client.%s.id
914-
name = "%s"
925+
client_id = keycloak_openid_client.%s.id # 6 importedClientIdRef
926+
name = "%s" # 7 nestedRole.Name
915927
import = true
916928
}
917-
`, importedClientIdRef, *nestedRole.ClientId, importedRoleRef, importedClientIdRef, nestedRole.Name)
929+
`, *nestedRole.ClientId, importedClientIdRef, importedClientIdRef, *nestedRole.ClientId, importedRoleRef, importedClientIdRef, nestedRole.Name)
918930
}
919931

920932
if i != 0 {

0 commit comments

Comments
 (0)