Skip to content

Commit

Permalink
added test cases for resource_tracking
Browse files Browse the repository at this point in the history
Signed-off-by: B Rahul <[email protected]>
  • Loading branch information
rahulbollisetty committed Oct 11, 2024
1 parent c5cfcd7 commit 09ec136
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 7 additions & 11 deletions util/argo/resource_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func (rt *resourceTracking) getAppInstanceValue(un *unstructured.Unstructured, i
return value
}

func (rt *resourceTracking) getAppInstanceIdValue(un *unstructured.Unstructured) *string {
appInstanceIdValue, err := argokube.GetAppInstanceAnnotation(un, common.AnnotationKeyAppInstanceID)
if err != nil {
return nil
}
return &appInstanceIdValue
func (rt *resourceTracking) getAppInstanceIdValue(un *unstructured.Unstructured) string {
appInstanceIdValue, err := argokube.GetAppInstanceAnnotation(un, common.AnnotationKeyAppInstanceID)
if err != nil {
return ""
}
return appInstanceIdValue
}

// GetAppName retrieve application name base on tracking method
Expand Down Expand Up @@ -133,11 +133,7 @@ func (rt *resourceTracking) GetAppInstance(un *unstructured.Unstructured, key st

// GetAppInstanceID retrieve instance ID of the resource.
func (rt *resourceTracking) GetAppInstanceID(un *unstructured.Unstructured) string {
appInstanceIdValue := rt.getAppInstanceIdValue(un)
if appInstanceIdValue == nil {
return ""
}
return *appInstanceIdValue
return rt.getAppInstanceIdValue(un)
}

// UnstructuredToAppInstanceValue will build the AppInstanceValue based
Expand Down
4 changes: 4 additions & 0 deletions util/argo/resource_tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func TestSetAppInstanceIdAnnotation(t *testing.T) {

value := resourceTracking.GetAppInstanceID(&obj)
assert.Equal(t, "argocd.com", value)

err = resourceTracking.SetAppInstanceID(&obj, "")
require.Error(t, err)
assert.Contains(t, err.Error(), "ArgoCD URL is missing")
}

func TestSetAppInstanceIdAnnotationNotFound(t *testing.T) {
Expand Down

0 comments on commit 09ec136

Please sign in to comment.