@@ -3,18 +3,19 @@ package tests
33import (
44 "context"
55 "fmt"
6+ "math/rand"
7+ "os"
8+ "reflect"
9+ "testing"
10+ "time"
11+
612 "github.com/permitio/permit-golang/pkg/config"
713 "github.com/permitio/permit-golang/pkg/enforcement"
814 PermitErrors "github.com/permitio/permit-golang/pkg/errors"
915 "github.com/permitio/permit-golang/pkg/models"
1016 "github.com/permitio/permit-golang/pkg/permit"
1117 "github.com/stretchr/testify/assert"
1218 "go.uber.org/zap"
13- "math/rand"
14- "os"
15- "reflect"
16- "testing"
17- "time"
1819)
1920
2021var runId = randId ()
@@ -135,8 +136,9 @@ func checkBulk(ctx context.Context, t *testing.T, permitClient *permit.Client, r
135136
136137func factsApi (ctx context.Context , t * testing.T , permitContext * config.PermitContext , logger * zap.Logger , token string ) {
137138 permitClient := permit .New (config .NewConfigBuilder (token ).
138- WithPdpUrl (os .Getenv ("PDP_URL" )).
139- WithApiUrl (os .Getenv ("API_URL" )).
139+ WithPdpUrl ("http://localhost:7766" ).
140+ // WithPdpUrl(os.Getenv("PDP_URL")).
141+ WithApiUrl ("https://api.permit.io" ).
140142 WithContext (permitContext ).
141143 WithLogger (logger ).
142144 WithProxyFactsViaPDP (true ).
@@ -172,6 +174,32 @@ func factsApi(ctx context.Context, t *testing.T, permitContext *config.PermitCon
172174 assert .NoError (t , err )
173175 assert .True (t , allowed )
174176}
177+
178+ func TestFactsIntegration (t * testing.T ) {
179+ logger := zap .NewExample ()
180+ ctx := context .Background ()
181+
182+ project := os .Getenv ("PROJECT" )
183+
184+ if project == "" {
185+ t .Fatal ("PROJECT is not set" )
186+ }
187+
188+ env := os .Getenv ("ENV" )
189+
190+ if env == "" {
191+ t .Fatal ("ENV is not set" )
192+ }
193+
194+ token := os .Getenv ("PDP_API_KEY" )
195+ if token == "" {
196+ t .Fatal ("PDP_API_KEY is not set" )
197+ }
198+ permitContext := config .NewPermitContext (config .EnvironmentAPIKeyLevel , project , env )
199+
200+ // Test Facts API
201+ factsApi (ctx , t , permitContext , logger , token )
202+ }
175203func TestIntegration (t * testing.T ) {
176204 logger := zap .NewExample ()
177205 ctx := context .Background ()
@@ -210,10 +238,7 @@ func TestIntegration(t *testing.T) {
210238 WithApiUrl (os .Getenv ("API_URL" )).
211239 WithContext (permitContext ).
212240 WithLogger (logger ).
213- Build ())
214-
215- // Test Facts API
216- factsApi (ctx , t , permitContext , logger , token )
241+ Build ())
217242
218243 // Create a user
219244 userCreate := * models .NewUserCreate (userKey )
@@ -344,7 +369,7 @@ func TestIntegration(t *testing.T) {
344369 // Assign role to user
345370 _ , err = permitClient .Api .Users .AssignRole (ctx , userKey , roleKey , tenantKey )
346371 assert .NoError (t , err )
347- time .Sleep (30 * time .Second )
372+ time .Sleep (15 * time .Second )
348373
349374 // Testing List Tenants Users
350375 // Note - Dependent on the user creation above -- consider decoupling this test from the user creation
0 commit comments