Skip to content

Commit

Permalink
S-109371/ S-109373 SDK improvements - Reporting record type, QueryPa…
Browse files Browse the repository at this point in the history
…ram creation inline method, Mocking improvemnts and Task assertions fix (#61)

* * Helper method to create QueryParam directly
* Adding types to all reporting records
* Fixing Task test assertions
* Respect query variables in mock http client

* PR Changes

* Removing the CodeComplianceRecord method, reporting usage in SDK will be refactored with another task
  • Loading branch information
RolandasJas committed May 20, 2024
1 parent 95c44a9 commit 8e387aa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions http/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type QueryParam struct {
value string
}

func NewQueryParam(key string, value string) QueryParam {
return QueryParam{
key: key,
value: value,
}
}

// Pair sets the key-value pair for the QueryParam.
func (q *QueryParam) Pair(key string, value string) {
q.key = key
Expand Down
4 changes: 3 additions & 1 deletion task/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ func (r *Result) ReportingRecord(record interface{}) *Result {
// CreateDeploymentRecord creates a new reporting record for deployment.
func CreateDeploymentRecord(client *http.HttpClient, taskInfo *DeploymentRecordTaskInfo, status DeploymentStatus) *DeploymentRecord {
record := &DeploymentRecord{
Type: "udm.DeploymentRecord",
ReportingRecord: ReportingRecord{
Type: "udm.DeploymentRecord",
},
}
record.Status = status
serverUrl := client.GetBaseUrl()
Expand Down
2 changes: 1 addition & 1 deletion task/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type DeploymentRecordTaskInfo struct {
// ReportingRecord represents the record produced by task.
type ReportingRecord struct {
Id string `json:"id"`
Type string `json:"type"`
TargetId string `json:"targetId,omitempty"`
ServerUrl string `json:"serverUrl,omitempty"`
ServerUser string `json:"serverUser,omitempty"`
Expand Down Expand Up @@ -112,7 +113,6 @@ type BuildRecord struct {
// DeploymentRecord represents the record for deployment.
type DeploymentRecord struct {
ReportingRecord
Type string `json:"type"`
DeploymentTask string `json:"deploymentTask,omitempty"`
DeploymentTaskUrl string `json:"deploymentTask_url,omitempty"`
ApplicationName string `json:"applicationName,omitempty"`
Expand Down
9 changes: 7 additions & 2 deletions test/mock_http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ func NewMockHttpClient(mocks []MockResult) rest.HTTPClient {

// getPath returns the path from the provided URL.
func getPath(url *url.URL) string {
var path string
if url.RawPath != "" {
return url.RawPath
path = url.RawPath
} else {
return url.Path
path = url.Path
}
if url.RawQuery != "" {
return path + "?" + url.RawQuery
}
return path
}

// Do performs the mock HTTP request.
Expand Down
16 changes: 6 additions & 10 deletions test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ import (

// AssertRequestResult compares the actual and expected results of a task in a testing context.
func AssertRequestResult(t *testing.T, actual *task.Result, actualErr error, expected *task.Result, expectedErr error) {
if actualErr != nil {
if actualErr != nil || expectedErr != nil {
if !reflect.DeepEqual(actualErr, expectedErr) {
t.Fatalf("Actual: [%v]; Expected: [%v]", actualErr, expectedErr)
} else {
t.Logf("Success!")
}
} else {
mapResult, err := actual.Get()
if !reflect.DeepEqual(err, expectedErr) {
t.Fatalf("Actual: [%v]; Expected: [%v]", err, expectedErr)
mapResult, mapErr := actual.Get()
expectedMap, expectedMapErr := expected.Get()
if !reflect.DeepEqual(mapErr, expectedMapErr) {
t.Fatalf("Actual: [%v]; Expected: [%v]", mapErr, expectedMapErr)
}
response, err := json.Marshal(mapResult)
if !reflect.DeepEqual(err, expectedErr) {
t.Fatalf("Actual: [%v]; Expected: [%v]", err, expectedErr)
}

expectedMap, err := expected.Get()
if err != nil {
t.Fatalf("Error while trying to get value from expected: [%v]", err)
t.Fatalf("Error while trying to marshal actual: [%v]", err)
}

expectedJson, err := json.Marshal(expectedMap)
Expand Down

0 comments on commit 8e387aa

Please sign in to comment.