Skip to content

Commit

Permalink
fix broken after merge unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-codefresh committed Jan 7, 2025
1 parent f087fad commit bac28c1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ func TestNormalizeApplication(t *testing.T) {
normalized := false
fakeAppCs.AddReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) {
if patchAction, ok := action.(kubetesting.PatchAction); ok {
if string(patchAction.GetPatch()) == `{"spec":{"project":"default"},"status":{"sync":{"comparedTo":{"destination":{},"source":{"repoURL":""}}}}}` {
if string(patchAction.GetPatch()) == `{"spec":{"project":"default"}}` {
normalized = true
}
}
Expand Down
2 changes: 2 additions & 0 deletions event_reporter/reporter/event_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
func getMockedArgoTrackingMetadata() *ArgoTrackingMetadata {
appInstanceLabelKey := common.LabelKeyAppInstance
trackingMethod := argo.TrackingMethodLabel
installationID := ""

return &ArgoTrackingMetadata{
AppInstanceLabelKey: &appInstanceLabelKey,
TrackingMethod: &trackingMethod,
InstallationID: &installationID,
}
}

Expand Down
8 changes: 4 additions & 4 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,8 +1576,8 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
return nil, err
}

resManifests := make([]*apiclient.Manifest, len(manifests))
for i, m := range manifests {
resManifests := make([]*apiclient.Manifest, 0)
for _, m := range manifests {
if q.AppLabelKey != "" && q.AppName != "" && !kube.IsCRD(m.obj) {
err = resourceTracking.SetAppInstance(m.obj, q.AppLabelKey, q.AppName, q.Namespace, v1alpha1.TrackingMethod(q.TrackingMethod), q.InstallationID)
if err != nil {
Expand All @@ -1590,12 +1590,12 @@ func GenerateManifests(ctx context.Context, appPath, repoRoot, revision string,
return nil, err
}

resManifests[i] = &apiclient.Manifest{
resManifests = append(resManifests, &apiclient.Manifest{
CompiledManifest: string(manifestStr),
RawManifest: string(m.rawManifest),
Path: m.path,
Line: int32(m.line),
}
})
}

res := apiclient.ManifestResponse{
Expand Down
16 changes: 12 additions & 4 deletions reposerver/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func newCacheMocksWithOpts(repoCacheExpiration, revisionCacheExpiration, revisio
}
}

func applyCfGitClientMocks(gitClientMock *gitmocks.Client) {
gitClientMock.On("RevisionMetadata", mock.Anything).Return(nil, errors.New("cant fetch metadata"))
}

func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *gitmocks.Client, *repoCacheMocks) {
root, err := filepath.Abs(root)
if err != nil {
Expand All @@ -113,7 +117,6 @@ func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *git
gitClient.On("CommitSHA").Return(mock.Anything, nil)
gitClient.On("Root").Return(root)
gitClient.On("IsAnnotatedTag").Return(false)
gitClient.On("RevisionMetadata", mock.Anything).Return(nil, errors.New("cant fetch metadata"))
if signed {
gitClient.On("VerifyCommitSignature", mock.Anything).Return(testSignature, nil)
} else {
Expand Down Expand Up @@ -163,12 +166,14 @@ func newServiceWithOpt(t *testing.T, cf clientFunc, root string) (*Service, *git
}

func newService(t *testing.T, root string) *Service {
service, _, _ := newServiceWithMocks(t, root, false)
service, gm, _ := newServiceWithMocks(t, root, false)
applyCfGitClientMocks(gm)
return service
}

func newServiceWithSignature(t *testing.T, root string) *Service {
service, _, _ := newServiceWithMocks(t, root, true)
service, gm, _ := newServiceWithMocks(t, root, true)
applyCfGitClientMocks(gm)
return service
}

Expand Down Expand Up @@ -336,6 +341,7 @@ func TestGenerateManifests_K8SAPIResetCache(t *testing.T) {

func TestGenerateManifests_EmptyCache(t *testing.T) {
service, gitMocks, mockCache := newServiceWithMocks(t, "../../manifests/base", false)
applyCfGitClientMocks(gitMocks)

src := argoappv1.ApplicationSource{Path: "."}
q := apiclient.ManifestRequest{
Expand Down Expand Up @@ -490,6 +496,7 @@ func TestGenerateManifestsHelmWithRefs_CachedNoLsRemote(t *testing.T) {
func TestHelmManifestFromChartRepo(t *testing.T) {
root := t.TempDir()
service, gitMocks, mockCache := newServiceWithMocks(t, root, false)
applyCfGitClientMocks(gitMocks)
source := &argoappv1.ApplicationSource{Chart: "my-chart", TargetRevision: ">= 1.0.0"}
request := &apiclient.ManifestRequest{
Repo: &argoappv1.Repository{}, ApplicationSource: source, NoCache: true, ProjectName: "something",
Expand Down Expand Up @@ -657,6 +664,7 @@ func TestHelmChartReferencingExternalValues_OutOfBounds_Symlink(t *testing.T) {

func TestGenerateManifestsUseExactRevision(t *testing.T) {
service, gitClient, _ := newServiceWithMocks(t, ".", false)
applyCfGitClientMocks(gitClient)

src := argoappv1.ApplicationSource{Path: "./testdata/recurse", Directory: &argoappv1.ApplicationSourceDirectory{Recurse: true}}

Expand All @@ -683,7 +691,7 @@ func TestRecurseManifestsInDir(t *testing.T) {

res1, err := service.GenerateManifest(context.Background(), &q)
require.NoError(t, err)
assert.Len(t, res1.Manifests, 2)
assert.Len(t, res1.Manifests, 4)
}

func TestInvalidManifestsInDir(t *testing.T) {
Expand Down
14 changes: 0 additions & 14 deletions util/db/repository_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,6 @@ func TestSecretsRepositoryBackend_GetRepository(t *testing.T) {
"project": []byte("testProject"),
},
},
&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: testNamespace,
Name: "other-user-managed",
Labels: map[string]string{common.LabelKeySecretType: common.LabelValueSecretTypeRepository},
},
Data: map[string][]byte{
"name": []byte("Scoped UserManagedRepo"),
"url": []byte("[email protected]:argoproj/argoproj.git"),
"username": []byte("someOtherUsername"),
"password": []byte("someOtherPassword"),
"project": []byte("testProject"),
},
},
}

clientset := getClientset(map[string]string{}, repoSecrets...)
Expand Down

0 comments on commit bac28c1

Please sign in to comment.