generated from konveyor/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFR] Ginkgo test: export applications as tasks to Jira (#56)
* Adding new TC: export applications to Jira Signed-off-by: Maayan Hadasi <mguetta@redhat.com> * Using conf variable in utils Signed-off-by: Maayan Hadasi <mguetta@redhat.com> --------- Signed-off-by: Maayan Hadasi <mguetta@redhat.com>
- Loading branch information
Showing
7 changed files
with
200 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package data | ||
|
||
type ExportApplicationsCase struct { | ||
JiraInstance JiraInstanceTC | ||
NumOfApps int | ||
TicketKind string | ||
TicketParent string | ||
} |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package migrationwave | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/konveyor/go-konveyor-tests/config" | ||
"github.com/konveyor/go-konveyor-tests/data" | ||
"github.com/konveyor/go-konveyor-tests/hack/uniq" | ||
"github.com/konveyor/go-konveyor-tests/utils" | ||
"github.com/konveyor/tackle2-hub/api" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var ( | ||
jiraInstance utils.Jira | ||
jiraIdentity api.Identity | ||
migrationWave api.MigrationWave | ||
issueIds []string | ||
appsToExport []api.Application | ||
) | ||
|
||
var _ = Describe("Export applications", func() { | ||
AfterEach(func() { | ||
// Resources cleanup | ||
if keep, _ := strconv.ParseBool(config.Config.KEEP); keep { | ||
return | ||
} | ||
Expect(utils.Tracker.Delete(jiraInstance.ID)).To(Succeed()) | ||
Expect(utils.Identity.Delete(jiraIdentity.ID)).To(Succeed()) | ||
Expect(utils.MigrationWave.Delete((migrationWave.ID))).To(Succeed()) /* Associated api.Ticket objects are removed as well */ | ||
jiraInstance.DeleteJiraIssues(issueIds) | ||
utils.DeleteApplicationsBySlice(appsToExport) | ||
}) | ||
|
||
DescribeTable("", | ||
func(testCase data.ExportApplicationsCase) { | ||
appsToExport = utils.CreateMultipleApplications(testCase.NumOfApps) | ||
By("Create migration wave") | ||
uniq.MigrationWaveName(&migrationWave) | ||
err := utils.MigrationWave.Create(&migrationWave) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Manage applications") | ||
for i := 0; i < len(appsToExport); i++ { | ||
migrationWave.Applications = append(migrationWave.Applications, api.Ref{ID: appsToExport[i].ID, Name: appsToExport[i].Name}) | ||
} | ||
err = utils.MigrationWave.Update(&migrationWave) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("Create Jira instance") | ||
jiraIdentity, jiraInstance = utils.CreateJiraInstance(testCase.JiraInstance) | ||
|
||
By("Check ticket was created") | ||
for i := 0; i < len(appsToExport); i++ { | ||
ticket := api.Ticket{Kind: testCase.TicketKind, Parent: testCase.TicketParent, Application: api.Ref{ID: appsToExport[i].ID}, | ||
Tracker: api.Ref{ID: jiraInstance.ID}} | ||
utils.Ticket.Create(&ticket) | ||
|
||
// Wait for reference field to be populated | ||
var got *api.Ticket | ||
var retry, _ = strconv.Atoi(config.Config.RETRY_NUM) | ||
for i := 0; i < retry; i++ { | ||
got, err = utils.Ticket.Get(ticket.ID) | ||
if err != nil || got.Reference != "" { | ||
break | ||
} | ||
time.Sleep(5 * time.Second) | ||
} | ||
Expect(got.Reference).NotTo(BeEmpty()) | ||
issueIds = append(issueIds, got.Reference) | ||
} | ||
|
||
}, | ||
Entry("Export applications as a task", data.ExportApplicationsCase{ | ||
JiraInstance: data.JiraCloud, | ||
NumOfApps: 3, | ||
TicketKind: "10007", /* Task issuetypeId */ | ||
TicketParent: "10001" /* mta_integration projectId */})) | ||
}) |
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/base64" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/konveyor/go-konveyor-tests/data" | ||
"github.com/konveyor/go-konveyor-tests/hack/uniq" | ||
"github.com/konveyor/tackle2-hub/api" | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
type Jira api.Tracker | ||
|
||
func CreateJiraInstance(data data.JiraInstanceTC) (api.Identity, Jira) { | ||
jiraIdentity := data.Identity | ||
uniq.IdentityName(&jiraIdentity) | ||
err := Identity.Create(&jiraIdentity) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
|
||
jiraInstance := Jira{ | ||
URL: data.JiraUrl, | ||
Kind: data.JiraKind, | ||
Identity: api.Ref{ | ||
ID: jiraIdentity.ID, | ||
Name: jiraIdentity.Name, | ||
}, | ||
} | ||
uniq.TrackerName((*api.Tracker)(&jiraInstance)) | ||
err = Tracker.Create((*api.Tracker)(&jiraInstance)) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
|
||
// Wait for connection succeeded | ||
var jira *api.Tracker | ||
var retry, _ = strconv.Atoi(conf.RETRY_NUM) | ||
for i := 0; i < retry; i++ { | ||
jira, err = Tracker.Get(jiraInstance.ID) | ||
if err != nil || jira.Connected { | ||
break | ||
} | ||
time.Sleep(5 * time.Second) | ||
} | ||
gomega.Expect(jira.Connected).To(gomega.BeTrue()) | ||
|
||
return jiraIdentity, jiraInstance | ||
} | ||
|
||
func (r *Jira) DeleteJiraIssues(issues []string) { | ||
for i := 0; i < len(issues); i++ { | ||
url := conf.JIRA_CLOUD_URL + "/rest/api/3/issue/" + issues[i] | ||
r.sendJiraRequest(url, "DELETE") | ||
} | ||
} | ||
|
||
func (r *Jira) sendJiraRequest(url string, method string) { | ||
// Create a basic authentication string | ||
basicAuth := "Basic " + | ||
base64.StdEncoding.EncodeToString([]byte(conf.JIRA_CLOUD_USERNAME+":"+conf.JIRA_CLOUD_PASSWORD)) | ||
|
||
// Create a bearer authentication string | ||
bearerAuth := "Bearer " + conf.JIRA_CLOUD_PASSWORD | ||
|
||
// Create a request | ||
request, _ := http.NewRequest(method, url, nil) | ||
|
||
// Set the authorization header | ||
request.Header.Set("Authorization", basicAuth) | ||
if r.Kind == "on-permise" { | ||
request.Header.Set("Authorization", bearerAuth) | ||
} | ||
|
||
// Make the request | ||
client := http.Client{} | ||
response, err := client.Do(request) | ||
gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||
|
||
// Ensure that the response body is closed when the function returns | ||
defer response.Body.Close() | ||
} |
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