-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always provide mock clients during testing
- Loading branch information
1 parent
59a743c
commit 3ca5796
Showing
4 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,7 @@ func TestReconcile(t *testing.T) { | |
} | ||
|
||
mocks := mocks{ | ||
artifactRegistry: &fakeArtifactRegistry{}, | ||
iam: test.HttpServerWithHandlers(t, []http.HandlerFunc{ | ||
func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(404) | ||
|
@@ -204,11 +205,11 @@ func TestReconcile(t *testing.T) { | |
}, | ||
}), | ||
} | ||
_, iamService := mocks.start(t, ctx) | ||
artifactRegistryClient, iamService := mocks.start(t, ctx) | ||
|
||
apiClient, _ := apiclient.NewMockClient(t) | ||
|
||
reconciler, err := google_gar_reconciler.New(ctx, managementProjectID, tenantDomain, workloadIdentityPoolName, google_gar_reconciler.WithIAMService(iamService)) | ||
reconciler, err := google_gar_reconciler.New(ctx, managementProjectID, tenantDomain, workloadIdentityPoolName, google_gar_reconciler.WithGarClient(artifactRegistryClient), google_gar_reconciler.WithIAMService(iamService)) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
@@ -224,6 +225,7 @@ func TestReconcile(t *testing.T) { | |
} | ||
|
||
mocks := mocks{ | ||
artifactRegistry: &fakeArtifactRegistry{}, | ||
iam: test.HttpServerWithHandlers(t, []http.HandlerFunc{ | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if err := json.NewEncoder(w).Encode(&expectedServiceAccount); err != nil { | ||
|
@@ -262,7 +264,7 @@ func TestReconcile(t *testing.T) { | |
}, | ||
}), | ||
} | ||
_, iamService := mocks.start(t, ctx) | ||
artifactregistryClient, iamService := mocks.start(t, ctx) | ||
|
||
apiClient, mockServer := apiclient.NewMockClient(t) | ||
mockServer.Reconcilers.EXPECT(). | ||
|
@@ -317,7 +319,7 @@ func TestReconcile(t *testing.T) { | |
}, nil). | ||
Once() | ||
|
||
reconciler, err := google_gar_reconciler.New(ctx, managementProjectID, tenantDomain, workloadIdentityPoolName, google_gar_reconciler.WithIAMService(iamService)) | ||
reconciler, err := google_gar_reconciler.New(ctx, managementProjectID, tenantDomain, workloadIdentityPoolName, google_gar_reconciler.WithGarClient(artifactregistryClient), google_gar_reconciler.WithIAMService(iamService)) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
@@ -580,7 +582,13 @@ func TestDelete(t *testing.T) { | |
|
||
apiClient, _ := apiclient.NewMockClient(t) | ||
|
||
reconciler, err := google_gar_reconciler.New(ctx, managementProjectID, tenantDomain, workloadIdentityPoolName) | ||
mocks := mocks{ | ||
artifactRegistry: &fakeArtifactRegistry{}, | ||
iam: test.HttpServerWithHandlers(t, []http.HandlerFunc{}), | ||
} | ||
artifactregistryClient, iamService := mocks.start(t, ctx) | ||
|
||
reconciler, err := google_gar_reconciler.New(ctx, managementProjectID, tenantDomain, workloadIdentityPoolName, google_gar_reconciler.WithGarClient(artifactregistryClient), google_gar_reconciler.WithIAMService(iamService)) | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
@@ -611,6 +619,7 @@ func TestDelete(t *testing.T) { | |
apiClient, _ := apiclient.NewMockClient(t) | ||
|
||
mockedClients := mocks{ | ||
artifactRegistry: &fakeArtifactRegistry{}, | ||
iam: test.HttpServerWithHandlers(t, []http.HandlerFunc{ | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if contains := "management-project-123/serviceAccounts/[email protected]"; !strings.Contains(r.URL.Path, contains) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters