Skip to content

Commit

Permalink
Leaf 4682 - test to delete tag nexus side
Browse files Browse the repository at this point in the history
  • Loading branch information
jampaul3 committed Feb 27, 2025
1 parent 51fda02 commit 3a7ddce
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions API-tests/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ func postNewGroup() string {
return c
}

func postNewTag(groupID string) string {
func postNewTag(groupID string, tag string) string {
postData := url.Values{}
if tag != "" {
postData.Set("tag", tag)
}
postData.Set("CSRFToken", CsrfToken)

res, _ := client.PostForm(RootOrgchartURL+`api/group/`+groupID+`/tag`, postData)
Expand All @@ -97,9 +100,12 @@ func importGroup(groupID string) string {
return c
}

func removeNexusGroup(postUrl string) error {
func removeFromNexus(postUrl string, tag string) error {

data := url.Values{}
if tag != "" {
data.Set("tag", tag)
}
data.Set("CSRFToken", CsrfToken)

req, err := http.NewRequest("DELETE", postUrl, strings.NewReader(data.Encode()))
Expand Down Expand Up @@ -144,7 +150,7 @@ func TestGroup_syncServices(t *testing.T) {
groupID := postNewGroup()
id, _ := strconv.Atoi(groupID)
var passed = false
postNewTag(groupID)
postNewTag(groupID, "")
importGroup(groupID)

// check that the group exists in both nexus and portal
Expand Down Expand Up @@ -176,7 +182,7 @@ func TestGroup_syncServices(t *testing.T) {
}

// remove this group from the nexus
err := removeNexusGroup(fmt.Sprintf("%sapi/group/%s", RootOrgchartURL, groupID))
err := removeFromNexus(fmt.Sprintf("%sapi/group/%s", RootOrgchartURL, groupID), "")

if err != nil {
t.Error(err)
Expand Down Expand Up @@ -219,3 +225,48 @@ func TestGroup_syncServices(t *testing.T) {
t.Errorf("Portal group was not removed and should have been")
}
}

func TestGroup_removeTag(t *testing.T) {
// add a tag to a group
id := "34"
id_int, _ := strconv.Atoi(id)
passed := false
tag_name := "Academy_Demo1"
postNewTag(id, tag_name)

// check to make sure tag was added
o_groups := getNexusGroup(RootOrgchartURL + `api/group/list`)

for _, o_group := range o_groups {
if id_int == o_group.GroupID {
passed = true
break
}
}

if passed == false {
t.Errorf("The tag was not found in this group")
}

// remove the tag
err := removeFromNexus(fmt.Sprintf("%sapi/group/%s/tag?", RootOrgchartURL, id), tag_name)

if err != nil {
t.Error(err)
}

// check to make sure tag was removed
passed = false
o_groups = getNexusGroup(RootOrgchartURL + `api/group/list`)

for _, o_group := range o_groups {
if (id_int == o_group.GroupID) && (tag_name == o_group.GroupTitle) {
passed = true
break
}
}

if passed == true {
t.Errorf("The tag was not removed from this group")
}
}

0 comments on commit 3a7ddce

Please sign in to comment.