Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit d48761a

Browse files
authored
Merge pull request #231 from galasa-dev/mcobbett-1824-log-every-error-raised
error from getcatalog is not lost now
2 parents 6e94b00 + ef918db commit d48761a

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

pkg/errors/errorMessage.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package errors
77

88
import (
99
"fmt"
10+
"log"
1011
"strconv"
1112
"strings"
1213
)
@@ -62,6 +63,7 @@ func NewGalasaError(msgType *MessageType, params ...interface{}) *GalasaError {
6263
galasaError.msgType = msgType
6364
galasaError.message = message
6465

66+
log.Println(message)
6567
if galasaError.msgType.IsStackTraceWanted {
6668
LogStackTrace()
6769
}
@@ -103,7 +105,7 @@ var (
103105
GALASA_ERROR_SUBMIT_REPORT_JUNIT_WRITE_FAIL = NewMessageType("GAL1015E: Failed to write test report junit results file %s. Reason is %s", 1015, STACK_TRACE_WANTED)
104106
GALASA_ERROR_EMPTY_PORTFOLIO = NewMessageType("GAL1016E: There are no tests in the test porfolio %s", 1016, STACK_TRACE_WANTED)
105107
GALASA_ERROR_TESTS_FAILED = NewMessageType("GAL1017E: Not all runs passed. %v failed.", 1017, STACK_TRACE_NOT_WANTED)
106-
GALASA_ERROR_NO_TESTS_SELECTED = NewMessageType("GAL1018E: No tests were selected.", 1018, STACK_TRACE_WANTED)
108+
GALASA_ERROR_NO_TESTS_SELECTED = NewMessageType("GAL1018E: No tests were selected.", 1018, STACK_TRACE_NOT_WANTED)
107109
GALASA_ERROR_PREPARE_INVALID_OVERRIDE = NewMessageType("GAL1019E: Invalid override '%v'", 1019, STACK_TRACE_WANTED)
108110
GALASA_ERROR_OPEN_LOG_FILE_FAILED = NewMessageType("GAL1020E: Failed to open log file '%s' for writing. Reason is %s", 1020, STACK_TRACE_NOT_WANTED)
109111
GALASA_ERROR_OPEN_PORTFOLIO_FILE_FAILED = NewMessageType("GAL1021E: Failed to open portfolio file '%s' for reading. Reason is %s", 1021, STACK_TRACE_WANTED)
@@ -230,7 +232,8 @@ var (
230232
GALASA_ERROR_FAILED_TO_COMPILE_PROPERTY_FIELD_REGEX = NewMessageType("GAL1141E: Unable to compile the regex pattern for Galasa Property field '%s'. Reason: '%s'", 1141, STACK_TRACE_NOT_WANTED)
231233
GALASA_ERROR_INVALID_PROPERTY_FIELD_FORMAT = NewMessageType("GAL1142E: The %s field value, '%s', provided does not match formatting requirements. "+
232234
"The %s field value must start with a character in the 'a-z' or 'A-Z' range, followed by any characters in the 'a'-'z', 'A'-'Z', '0'-'9', '.' (period), '-' (dash) or '_' (underscore) ranges only.", 1142, STACK_TRACE_NOT_WANTED)
233-
GALASA_ERROR_QUERY_RUNS_NON_OK_STATUS = NewMessageType("GAL1143E: Could not query run results. Server returned a non-200 code (%s)", 1143, STACK_TRACE_NOT_WANTED)
235+
GALASA_ERROR_QUERY_RUNS_NON_OK_STATUS = NewMessageType("GAL1143E: Could not query run results. Server returned a non-200 code (%s)", 1143, STACK_TRACE_NOT_WANTED)
236+
GALASA_ERROR_GET_TEST_CATALOG_CONTENTS_FAILED = NewMessageType("GAL1144E: Could not use url '%s' to retrieve the contents of the test catalog from stream '%s'. Http error from the Galasa server is '%v'", 1144, STACK_TRACE_NOT_WANTED)
234237

235238
// Warnings...
236239
GALASA_WARNING_MAVEN_NO_GALASA_OBR_REPO = NewMessageType("GAL2000W: Warning: Maven configuration file settings.xml should contain a reference to a Galasa repository so that the galasa OBR can be resolved. The official release repository is '%s', and 'pre-release' repository is '%s'", 2000, STACK_TRACE_WANTED)

pkg/launcher/remoteLauncher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (launcher *RemoteLauncher) GetStreams() ([]string, error) {
132132
// When passed an array of GalasaProperty objects, extract the stream names from them.
133133
func getStreamNamesFromProperties(properties []galasaapi.GalasaProperty) ([]string, error) {
134134
var err error
135-
var streams []string = make([]string,0)
135+
var streams []string = make([]string, 0)
136136
for _, property := range properties {
137137
propertyNamePtr := property.GetMetadata().Name
138138

@@ -168,7 +168,7 @@ func (launcher *RemoteLauncher) GetTestCatalog(stream string) (TestCatalog, erro
168168
var resp *http.Response
169169
resp, err = http.Get(*cpsProperty.Value)
170170
if err != nil {
171-
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_PROPERTY_GET_FAILED, *cpsProperty.Value, stream, err)
171+
err = galasaErrors.NewGalasaError(galasaErrors.GALASA_ERROR_GET_TEST_CATALOG_CONTENTS_FAILED, *cpsProperty.Value, stream, err)
172172
} else {
173173
defer resp.Body.Close()
174174

@@ -188,5 +188,5 @@ func (launcher *RemoteLauncher) GetTestCatalog(stream string) (TestCatalog, erro
188188
}
189189
}
190190

191-
return testCatalog, nil
191+
return testCatalog, err
192192
}

pkg/launcher/remoteLauncher_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
package launcher
77

88
import (
9+
"encoding/json"
10+
"fmt"
11+
"net/http"
12+
"net/http/httptest"
913
"testing"
1014

15+
"github.com/galasa-dev/cli/pkg/api"
1116
"github.com/galasa-dev/cli/pkg/galasaapi"
1217
"github.com/stretchr/testify/assert"
1318
)
@@ -53,4 +58,37 @@ func TestProcessingEmptyPropertiesListExtractsZeroStreamsOk(t *testing.T) {
5358
assert.Equal(t, 0, len(streams))
5459
}
5560

61+
func TestGetTestCatalogHttpErrorGetsReported(t *testing.T) {
62+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
63+
fmt.Printf("URL arrived at the mock test server: %s\n", r.RequestURI)
64+
switch r.RequestURI {
65+
case "/cps/namespace/framework/prefix/test.stream.myStream/suffix/location":
5666

67+
w.Header().Set("Content-Type", "application/json")
68+
w.WriteHeader(http.StatusOK)
69+
70+
name := "mycpsPropName"
71+
value := "a duff value" // This is intentionally duff, which will cause an HTTP error when the production code tries to GET using this as a URL.
72+
payload := galasaapi.CpsProperty{
73+
Name: &name,
74+
Value: &value,
75+
}
76+
payloadBytes, _ := json.Marshal(payload)
77+
w.Write(payloadBytes)
78+
79+
fmt.Printf("mock server sending payload: %s\n", string(payloadBytes))
80+
81+
}
82+
}))
83+
defer server.Close()
84+
85+
apiServerUrl := server.URL
86+
apiClient := api.InitialiseAPI(apiServerUrl)
87+
88+
launcher := NewRemoteLauncher(apiServerUrl, apiClient)
89+
90+
_, err := launcher.GetTestCatalog("myStream")
91+
92+
assert.NotNil(t, err)
93+
assert.ErrorContains(t, err, "GAL1144E") // Failed to get the test catalog.
94+
}

0 commit comments

Comments
 (0)