Skip to content

Commit

Permalink
Add tests for keycloak (#459)
Browse files Browse the repository at this point in the history
pulumi/pulumi-terraform-bridge#1849

This PR adds tests for the following resources:

index_grouproles
index_role
index_user
authentication_executionconfig
index_realmevents
index_group
authentication_execution
index_realm
  • Loading branch information
VenelinMartinov authored Jun 7, 2024
1 parent 10941e1 commit 2ad0622
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .ci-mgmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ actions:
run: make upstream
- name: Setup local Keycloak
run: make -C upstream local
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
pulumiConvert: 1
3 changes: 3 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ jobs:
run: make upstream
- name: Setup local Keycloak
run: make -C upstream local
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ jobs:
run: make upstream
- name: Setup local Keycloak
run: make -C upstream local
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ jobs:
run: make upstream
- name: Setup local Keycloak
run: make -C upstream local
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ jobs:
run: make upstream
- name: Setup local Keycloak
run: make -C upstream local
- name: Run provider tests
run: |
cd provider && go test -v -json -count=1 -cover -timeout 2h -tags=${{ matrix.language }} -parallel 4 . 2>&1 | tee /tmp/gotest.log | gotestfmt
- name: Run tests
if: matrix.testTarget == 'local'
run: cd examples && go test -v -json -count=1 -cover -timeout 2h -tags=${{
Expand Down
6 changes: 5 additions & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ replace (

require (
github.com/mrparkers/terraform-provider-keycloak v0.0.0-00010101000000-000000000000
github.com/pulumi/providertest v0.0.11
github.com/pulumi/pulumi-terraform-bridge/v3 v3.84.0
github.com/pulumi/pulumi/sdk/v3 v3.118.0
github.com/stretchr/testify v1.9.0
)

require (
Expand Down Expand Up @@ -78,6 +80,7 @@ require (
github.com/ettle/strcase v0.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
Expand Down Expand Up @@ -162,6 +165,7 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/natefinch/atomic v1.0.1 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
Expand Down Expand Up @@ -196,7 +200,6 @@ require (
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
Expand Down Expand Up @@ -238,6 +241,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/frand v1.4.2 // indirect
Expand Down
21 changes: 21 additions & 0 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1385,9 +1385,18 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 h1:Uc+IZ7gYqAf/rSGFplbWBSHaGolEQlNLgMgSE3ccnIQ=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813/go.mod h1:P+oSoE9yhSRvsmYyZsshflcR6ePWYLql6UU1amW13IM=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gkampitakis/ciinfo v0.3.0 h1:gWZlOC2+RYYttL0hBqcoQhM7h1qNkVqvRCV1fOvpAv8=
github.com/gkampitakis/ciinfo v0.3.0/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M=
github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk=
github.com/gkampitakis/go-snaps v0.4.9 h1:x6+GEQeYWC+cnLNsHK5uXXgEQADmlH/1EqMrjfXjzk8=
github.com/gkampitakis/go-snaps v0.4.9/go.mod h1:8HW4KX3JKV8M0GSw69CvT+Jqhd1AlBPMPpBfjBI3bdY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
Expand Down Expand Up @@ -1825,6 +1834,8 @@ github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAm
github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
Expand Down Expand Up @@ -2002,6 +2013,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/texttheater/golang-levenshtein v1.0.1 h1:+cRNoVrfiwufQPhoMzB6N0Yf/Mqajr6t1lOv8GyGE2U=
github.com/texttheater/golang-levenshtein v1.0.1/go.mod h1:PYAKrbF5sAiq9wd+H82hs7gNaen0CplQ9uvm6+enD/8=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 h1:X9dsIWPuuEJlPX//UmRKophhOKCGXc46RVIGuttks68=
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7/go.mod h1:UxoP3EypF8JfGEjAII8jx1q8rQyDnX8qdTCs/UQBVIE=
github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o=
Expand Down Expand Up @@ -2412,6 +2431,7 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down Expand Up @@ -2931,6 +2951,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
Expand Down
125 changes: 125 additions & 0 deletions provider/provider_program_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//go:build !go && !nodejs && !python && !dotnet
// +build !go,!nodejs,!python,!dotnet

package keycloak

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"

"github.com/pulumi/providertest"
"github.com/pulumi/providertest/optproviderupgrade"
"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/assertpreview"
"github.com/pulumi/providertest/pulumitest/opttest"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
)

const providerName = "keycloak"
const defaultBaselineVersion = "5.3.1"

var programs = []string{
"test-programs/index_grouproles",
"test-programs/index_role",
"test-programs/index_user",
"test-programs/authentication_executionconfig",
"test-programs/index_realmevents",
"test-programs/index_group",
"test-programs/authentication_execution",
"test-programs/index_realm",
}

func TestUpgradeCoverage(t *testing.T) {
providertest.ReportUpgradeCoverage(t)
}

type UpgradeTestOpts struct {
baselineVersion string
assertFunc func(*testing.T, auto.PreviewResult)
config map[string]string
}

func WithBaselineVersion(baselineVersion string) func(opts *UpgradeTestOpts) {
return func(opts *UpgradeTestOpts) {
opts.baselineVersion = baselineVersion
}
}

func WithAssertFunc(assertFunc func(*testing.T, auto.PreviewResult)) func(opts *UpgradeTestOpts) {
return func(opts *UpgradeTestOpts) {
opts.assertFunc = assertFunc
}
}

func WithConfig(config map[string]string) func(opts *UpgradeTestOpts) {
return func(opts *UpgradeTestOpts) {
opts.config = config
}
}
func testProviderUpgrade(t *testing.T, dir string, opts ...func(*UpgradeTestOpts)) {
options := &UpgradeTestOpts{}
for _, o := range opts {
o(options)
}
testProviderUpgradeWithOpts(t, dir, options.baselineVersion, options.config, options.assertFunc)
}

func testProviderUpgradeWithOpts(
t *testing.T, dir, baselineVersion string, config map[string]string,
assertFunction func(*testing.T, auto.PreviewResult),
) {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without credentials")
}
cwd, err := os.Getwd()
require.NoError(t, err)
if baselineVersion == "" {
baselineVersion = defaultBaselineVersion
}
test := pulumitest.NewPulumiTest(t, dir,
opttest.DownloadProviderVersion(providerName, baselineVersion),
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")),
)
for k, v := range config {
test.SetConfig(k, v)
}
result := providertest.PreviewProviderUpgrade(test, providerName, baselineVersion, optproviderupgrade.DisableAttach())
if assertFunction != nil {
assertFunction(t, result)
} else {
assertpreview.HasNoReplacements(t, result)
}
}

func testProgram(t *testing.T, dir string) {
if testing.Short() {
t.Skipf("Skipping in testing.Short() mode, assuming this is a CI run without credentials")
}
cwd, err := os.Getwd()
require.NoError(t, err)
test := pulumitest.NewPulumiTest(t, dir,
opttest.LocalProviderPath(providerName, filepath.Join(cwd, "..", "bin")),
opttest.SkipInstall(),
)
test.Up()
}

func TestPrograms(t *testing.T) {
for _, p := range programs {
t.Run(p, func(t *testing.T) {
testProgram(t, p)
})
}
}

func TestProgramsUpgrade(t *testing.T) {
t.Skipf("skip upgrade tests for now as we have not recorded them.")
for _, p := range programs {
t.Run(p, func(t *testing.T) {
testProviderUpgrade(t, p)
})
}
}
2 changes: 2 additions & 0 deletions provider/test-programs/authentication_execution/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
26 changes: 26 additions & 0 deletions provider/test-programs/authentication_execution/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: authentication_executionh1UGP0Fkk0eT
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/78b9933c-6dd9-4b72-946e-68edc38eae64.zip
resources:
keycloakAuthExecution:
properties:
authenticator: auth-cookie
parentFlowAlias: ${keycloakAuthFlow.alias}
realmId: ${keycloakRealm.realm}
requirement: REQUIRED
type: keycloak:authentication:Execution
keycloakAuthFlow:
properties:
alias: custom-auth-flow
description: A custom authentication flow
realmId: ${keycloakRealm.realm}
type: keycloak:authentication:Flow
keycloakRealm:
properties:
enabled: true
realm: example-realm
type: keycloak:Realm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
35 changes: 35 additions & 0 deletions provider/test-programs/authentication_executionconfig/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: authentication_executionconfige7oBrvJ1p51V
runtime: yaml
description: ""
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/f5185d25-5cc4-482d-b8f9-9b7f0db546e5.zip
resources:
keycloakAuthenticationExecution:
properties:
authenticator: auth-cookie
parentFlowAlias: ${keycloakAuthenticationFlow.alias}
realmId: ${keycloakRealm.realm}
type: keycloak:authentication:Execution
keycloakAuthenticationExecutionConfig:
properties:
alias: execution-config
config:
user_attribute: username
executionId: ${keycloakAuthenticationExecution.id}
realmId: ${keycloakRealm.realm}
type: keycloak:authentication:ExecutionConfig
keycloakAuthenticationFlow:
properties:
alias: myflow
description: My Authentication Flow
providerId: basic-flow
realmId: ${keycloakRealm.realm}
type: keycloak:authentication:Flow
keycloakRealm:
properties:
displayName: My Realm
enabled: true
realm: myrealm
type: keycloak:Realm
2 changes: 2 additions & 0 deletions provider/test-programs/index_group/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
18 changes: 18 additions & 0 deletions provider/test-programs/index_group/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: index_groupcghckcNmry6y
runtime: yaml
description: A minimal Pulumi program that creates a Keycloak group with its dependencies
config:
pulumi:tags:
value:
pulumi:template: https://www.pulumi.com/ai/api/project/19fcc853-1bd3-4b46-b9fd-d1969fb095dc.zip
resources:
keycloakGroup:
properties:

realmId: ${keycloakRealm.id}
type: keycloak:Group
keycloakRealm:
properties:
enabled: true
realm: example-realm
type: keycloak:Realm
2 changes: 2 additions & 0 deletions provider/test-programs/index_grouproles/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

/Pulumi.*.yaml
Loading

0 comments on commit 2ad0622

Please sign in to comment.