Skip to content

Commit

Permalink
Use dependency injection with argocd client
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvarts committed Dec 4, 2024
1 parent bb890c1 commit b162746
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func getEnv(key, fallback string) string {
return fallback
}

func createArgoCdClients() (ac argoCdClients, err error) {
func CreateArgoCdClients() (ac argoCdClients, err error) {
plaintext, _ := strconv.ParseBool(getEnv("ARGOCD_PLAINTEXT", "false"))
insecure, _ := strconv.ParseBool(getEnv("ARGOCD_INSECURE", "false"))

Expand Down Expand Up @@ -320,7 +320,7 @@ func findArgocdApp(ctx context.Context, componentPath string, repo string, appCl
func SetArgoCDAppRevision(ctx context.Context, componentPath string, revision string, repo string, useSHALabelForArgoDicovery bool) error {
var foundApp *argoappv1.Application
var err error
ac, err := createArgoCdClients()
ac, err := CreateArgoCdClients()
if err != nil {
return fmt.Errorf("Error creating ArgoCD clients: %w", err)
}
Expand Down
18 changes: 5 additions & 13 deletions internal/pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,25 +325,17 @@ func TestFetchArgoDiffConcurrently(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

argoClients, err := createArgoCdClients()
if err != nil {
t.Errorf("error creating ArgoCD clients: %v", err)
}

// mock the argoClients
mockAppServiceClient := mocks.NewMockApplicationServiceClient(mockCtrl)
mockSettingsServiceClient := mocks.NewMockSettingsServiceClient(mockCtrl)
mockProjectServiceClient := mocks.NewMockProjectServiceClient(mockCtrl)
// fake InitArgoClients
InitArgoClients = func() (argoCdClients, error) {
argoClients := argoCdClients{
app: mockAppServiceClient,
setting: mockSettingsServiceClient,
project: mockProjectServiceClient,
}
return argoClients, nil
}

argoClients := argoCdClients{
app: mockAppServiceClient,
setting: mockSettingsServiceClient,
project: mockProjectServiceClient,
}
// slowReply simulates a slow reply from the server
slowReply := func(ctx context.Context, in any, opts ...any) {
time.Sleep(time.Second)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func handleChangedPREvent(ctx context.Context, mainGithubClientPair GhClientPair
ghPrClientDetails.PrLogger.Debugf("ArgoCD diff disabled for %s\n", componentPath)
}
}
argoClients, err := createArgoCdClients()
argoClients, err := argocd.CreateArgoCdClients()
if err != nil {
return fmt.Errorf("error creating ArgoCD clients: %w", err)
}
Expand Down

0 comments on commit b162746

Please sign in to comment.