Skip to content

Commit

Permalink
[Ginkgo] Parameterized test case: exporting apps as tasks (#74)
Browse files Browse the repository at this point in the history
* Adding export TCs

Signed-off-by: Maayan Hadasi <mguetta@redhat.com>

* README.md

Signed-off-by: Maayan Hadasi <mguetta@redhat.com>

---------

Signed-off-by: Maayan Hadasi <mguetta@redhat.com>
  • Loading branch information
mguetta1 committed Dec 14, 2023
1 parent 0e0c87e commit 09eac94
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 29 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Ensure that the required configuration variables are set as environment variable
Refer to the `README.md` files in each folder for test-specific configuration details.

- [e2e/jiraintegration](https://github.com/konveyor/go-konveyor-tests/blob/main/e2e/jiraintegration/README.md)
- [e2e/migrationwave](https://github.com/konveyor/go-konveyor-tests/blob/main/e2e/migrationwave/README.md)

## Code of Conduct

Expand Down
13 changes: 9 additions & 4 deletions data/jira_data.go → data/jira/jira_data.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package data
package jira

import (
. "github.com/konveyor/go-konveyor-tests/config"
Expand All @@ -11,6 +11,11 @@ type JiraInstanceTC struct {
JiraKind string
}

const (
JIRA_KIND_CLOUD = "jira-cloud"
JIRA_KIND_ONPREM = "jira-onprem"
)

// Set of valid instances for tests and reuse.
// Important: Do not use it directly to not affect other tests.
var (
Expand All @@ -21,7 +26,7 @@ var (
Password: Config.JIRA_CLOUD_PASSWORD,
},
JiraUrl: Config.JIRA_CLOUD_URL,
JiraKind: "jira-cloud",
JiraKind: JIRA_KIND_CLOUD,
}
JiraServer = JiraInstanceTC{
Identity: api.Identity{
Expand All @@ -30,14 +35,14 @@ var (
Password: Config.JIRA_SERVER_PASSWORD,
},
JiraUrl: Config.JIRA_SERVER_URL,
JiraKind: "jira-onprem",
JiraKind: JIRA_KIND_ONPREM,
}
JiraServerBearerToken = JiraInstanceTC{
Identity: api.Identity{
Kind: "bearer",
Key: Config.JIRA_SERVER_TOKEN,
},
JiraUrl: Config.JIRA_SERVER_URL,
JiraKind: "jira-onprem",
JiraKind: JIRA_KIND_ONPREM,
}
)
12 changes: 12 additions & 0 deletions data/migrationwave/migrationwave_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package migrationwave

import (
"github.com/konveyor/go-konveyor-tests/data/jira"
)

type ExportApplicationsCase struct {
JiraInstance jira.JiraInstanceTC
NumOfApps int
TicketKind string
TicketParent string
}
8 changes: 0 additions & 8 deletions data/migrationwave_data.go

This file was deleted.

10 changes: 5 additions & 5 deletions e2e/jiraintegration/jira_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"

"github.com/konveyor/go-konveyor-tests/config"
"github.com/konveyor/go-konveyor-tests/data"
"github.com/konveyor/go-konveyor-tests/data/jira"
"github.com/konveyor/go-konveyor-tests/utils"
"github.com/konveyor/tackle2-hub/api"
. "github.com/onsi/ginkgo/v2"
Expand All @@ -26,11 +26,11 @@ var _ = Describe("Jira connection", func() {
})

DescribeTable("",
func(testCase data.JiraInstanceTC) {
func(testCase jira.JiraInstanceTC) {
// Create Jira instance
jiraIdentity, jiraInstance = utils.CreateJiraInstance(testCase)
},
Entry("Jira cloud", data.JiraCloud),
Entry("Jira server with basic auth", data.JiraServer),
Entry("Jira server with bearer token", data.JiraServerBearerToken))
Entry("Jira cloud", jira.JiraCloud),
Entry("Jira server with basic auth", jira.JiraServer),
Entry("Jira server with bearer token", jira.JiraServerBearerToken))
})
7 changes: 7 additions & 0 deletions e2e/migrationwave/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Test Configuration

### Export applications

To add a test case, follow the structure of the `Entry` constructor and provide the relevant arguments.

To execute an `Entry`, run: `ginkgo -focus "Entry description"`.
29 changes: 24 additions & 5 deletions e2e/migrationwave/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"time"

"github.com/konveyor/go-konveyor-tests/config"
"github.com/konveyor/go-konveyor-tests/data"
"github.com/konveyor/go-konveyor-tests/data/jira"
"github.com/konveyor/go-konveyor-tests/data/migrationwave"
"github.com/konveyor/go-konveyor-tests/hack/uniq"
"github.com/konveyor/go-konveyor-tests/utils"
"github.com/konveyor/tackle2-hub/api"
Expand All @@ -22,6 +23,14 @@ var (
)

var _ = Describe("Export applications", func() {
BeforeEach(func() {
jiraInstance = utils.Jira{}
jiraIdentity = api.Identity{}
migrationWave = api.MigrationWave{}
issueIds = []string{}
appsToExport = []api.Application{}

})
AfterEach(func() {
// Resources cleanup
if keep, _ := strconv.ParseBool(config.Config.KEEP); keep {
Expand All @@ -35,7 +44,7 @@ var _ = Describe("Export applications", func() {
})

DescribeTable("",
func(testCase data.ExportApplicationsCase) {
func(testCase migrationwave.ExportApplicationsCase) {
appsToExport = utils.CreateMultipleApplications(testCase.NumOfApps)
By("Create migration wave")
uniq.MigrationWaveName(&migrationWave)
Expand Down Expand Up @@ -73,9 +82,19 @@ var _ = Describe("Export applications", func() {
}

},
Entry("Export applications as a task", data.ExportApplicationsCase{
JiraInstance: data.JiraCloud,
Entry("Export as task to jira cloud", migrationwave.ExportApplicationsCase{
JiraInstance: jira.JiraCloud,
NumOfApps: 3,
TicketKind: "10007", /* Task issuetypeId */
TicketParent: "10001" /* mta_integration projectId */}))
TicketParent: "10001" /* mta_integration projectId */}),
Entry("Export as task to jira server", migrationwave.ExportApplicationsCase{
JiraInstance: jira.JiraServer,
NumOfApps: 3,
TicketKind: "3", /* Task issuetypeId */
TicketParent: "12340621" /* mta-qe-test projectId */}),
Entry("Export as task to jira server using token", migrationwave.ExportApplicationsCase{
JiraInstance: jira.JiraServerBearerToken, /* Using token for Jira connection */
NumOfApps: 3,
TicketKind: "3", /* Task issuetypeId */
TicketParent: "12340621" /* mta-qe-test projectId */}))
})
25 changes: 18 additions & 7 deletions utils/jira_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ package utils

import (
"encoding/base64"
"fmt"
"net/http"
"strconv"
"time"

"github.com/konveyor/go-konveyor-tests/data"
"github.com/konveyor/go-konveyor-tests/data/jira"
"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) {
func CreateJiraInstance(data jira.JiraInstanceTC) (api.Identity, Jira) {
jiraIdentity := data.Identity
uniq.IdentityName(&jiraIdentity)
err := Identity.Create(&jiraIdentity)
Expand Down Expand Up @@ -48,9 +49,19 @@ func CreateJiraInstance(data data.JiraInstanceTC) (api.Identity, Jira) {
}

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")
if r.Kind == jira.JIRA_KIND_CLOUD {
for i := 0; i < len(issues); i++ {
url := r.URL + "/rest/api/3/issue/" + issues[i]
r.sendJiraRequest(url, "DELETE")
}
return
}
if r.Kind == jira.JIRA_KIND_ONPREM {
for i := 0; i < len(issues); i++ {
url := fmt.Sprintf("%s/rest/api/2/issue/%s/archive", r.URL, issues[i])
r.sendJiraRequest(url, "PUT")
}
return
}
}

Expand All @@ -60,14 +71,14 @@ func (r *Jira) sendJiraRequest(url string, method string) {
base64.StdEncoding.EncodeToString([]byte(conf.JIRA_CLOUD_USERNAME+":"+conf.JIRA_CLOUD_PASSWORD))

// Create a bearer authentication string
bearerAuth := "Bearer " + conf.JIRA_CLOUD_PASSWORD
bearerAuth := "Bearer " + conf.JIRA_SERVER_TOKEN

// Create a request
request, _ := http.NewRequest(method, url, nil)

// Set the authorization header
request.Header.Set("Authorization", basicAuth)
if r.Kind == "on-permise" {
if r.Kind == jira.JIRA_KIND_ONPREM {
request.Header.Set("Authorization", bearerAuth)
}

Expand Down

0 comments on commit 09eac94

Please sign in to comment.