From fba5a14831ece91bbe5d41d5a4d0a7d0f4c1bafb Mon Sep 17 00:00:00 2001 From: mehmet-yoti Date: Fri, 13 Oct 2023 12:12:00 +0100 Subject: [PATCH] SDK-2246:updates for pr checks --- _examples/idv/handlers.session.go | 1 - digitalidentity/service_test.go | 11 ++++------- .../share_session_notification_builder.go | 12 ++++++------ sonar-project.properties | 3 ++- yotierror/response.go | 10 +++++----- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/_examples/idv/handlers.session.go b/_examples/idv/handlers.session.go index 7d73b46be..76cf44de3 100644 --- a/_examples/idv/handlers.session.go +++ b/_examples/idv/handlers.session.go @@ -63,7 +63,6 @@ func pageFromSessionSpec(c *gin.Context, sessionSpec *create.SessionSpecificatio return } createSessionResult, err = client.CreateSession(sessionSpec) - if err != nil { c.HTML( http.StatusInternalServerError, diff --git a/digitalidentity/service_test.go b/digitalidentity/service_test.go index 3c2e10026..f1ddc6eaf 100644 --- a/digitalidentity/service_test.go +++ b/digitalidentity/service_test.go @@ -92,7 +92,7 @@ func createShareSessionWithErrorResponse(statusCode int, responseBody string) (* return CreateShareSession(client, &session, "sdkId", "https://apiurl", key) } -func ExampleGetShareSession() { +func TestGetShareSession(t *testing.T) { key := test.GetValidKey("../test/test-key.pem") mockSessionID := "SOME_SESSION_ID" mockClientSdkId := "SOME_CLIENT_SDK_ID" @@ -106,10 +106,7 @@ func ExampleGetShareSession() { }, } - result, err := GetShareSession(client, mockSessionID, mockClientSdkId, mockApiUrl, key) - if err != nil { - return - } - fmt.Printf("Status code: %s", result.Status) - // Output:Status code: SOME_STATUS + _, err := GetShareSession(client, mockSessionID, mockClientSdkId, mockApiUrl, key) + assert.NilError(t, err) + } diff --git a/digitalidentity/share_session_notification_builder.go b/digitalidentity/share_session_notification_builder.go index 2207a2099..6c873ebc6 100644 --- a/digitalidentity/share_session_notification_builder.go +++ b/digitalidentity/share_session_notification_builder.go @@ -9,7 +9,7 @@ type ShareSessionNotification struct { url string method *string verifyTLS *bool - headers *map[string][]string + headers map[string][]string } // ShareSessionNotificationBuilder builds Share Session Notification @@ -37,7 +37,7 @@ func (b *ShareSessionNotificationBuilder) WithVerifyTls(verifyTls bool) *ShareSe // WithHeaders set headers to Share Session Notification func (b *ShareSessionNotificationBuilder) WithHeaders(headers map[string][]string) *ShareSessionNotificationBuilder { - b.shareSessionNotification.headers = &headers + b.shareSessionNotification.headers = headers return b } @@ -49,10 +49,10 @@ func (b *ShareSessionNotificationBuilder) Build() (ShareSessionNotification, err // MarshalJSON returns the JSON encoding func (a *ShareSessionNotification) MarshalJSON() ([]byte, error) { return json.Marshal(&struct { - Url string `json:"url"` - Method *string `json:"method,omitempty"` - VerifyTls *bool `json:"verifyTls,omitempty"` - Headers *map[string][]string `json:"headers,omitempty"` + Url string `json:"url"` + Method *string `json:"method,omitempty"` + VerifyTls *bool `json:"verifyTls,omitempty"` + Headers map[string][]string `json:"headers,omitempty"` }{ Url: a.url, Method: a.method, diff --git a/sonar-project.properties b/sonar-project.properties index d0d2bff74..5cc996e09 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -11,4 +11,5 @@ sonar.go.coverage.reportPaths = coverage.out sonar.go.tests.reportPaths = sonar-report.json sonar.tests = . sonar.test.inclusions = **/*_test.go -sonar.coverage.exclusions = test/**/*,_examples/**/*,src/digitalidentity/** +sonar.coverage.exclusions = test/**/*,_examples/**/* +sonar.cpd.exclusions = src/digitalidentity/** diff --git a/yotierror/response.go b/yotierror/response.go index e15806cdf..75c689d29 100644 --- a/yotierror/response.go +++ b/yotierror/response.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" ) @@ -65,8 +65,8 @@ func formatResponseMessage(response *http.Response, httpErrorMessages ...map[int return defaultMessage } - body, _ := ioutil.ReadAll(response.Body) - response.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + body, _ := io.ReadAll(response.Body) + response.Body = io.NopCloser(bytes.NewBuffer(body)) var errorDO DataObject jsonError := json.Unmarshal(body, &errorDO) @@ -104,8 +104,8 @@ func formatHTTPError(message string, statusCode int, body []byte) string { func handleHTTPError(response *http.Response, errorMessages ...map[int]string) string { var body []byte if response.Body != nil { - body, _ = ioutil.ReadAll(response.Body) - response.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + body, _ = io.ReadAll(response.Body) + response.Body = io.NopCloser(bytes.NewBuffer(body)) } else { body = make([]byte, 0) }