Skip to content

Commit 7f17ac0

Browse files
authored
Extend supported test artifacts with text files [CI-5161] (#234)
* Extend supported test artifacts with text files [CI-5161]
1 parent 5ac534b commit 7f17ac0

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ func deployTestResults(config Config, logger loggerV2.Logger) {
470470
if i == 0 {
471471
logger.Printf("List of test results:")
472472
}
473-
if len(result.ImagePaths) > 0 {
474-
logger.Printf("- %s (generated by the %s) with %d attachment(s):", result.Name, stepNameWithIndex(result.StepInfo), len(result.ImagePaths))
475-
for _, pth := range result.ImagePaths {
473+
if len(result.AttachmentPaths) > 0 {
474+
logger.Printf("- %s (generated by the %s) with %d attachment(s):", result.Name, stepNameWithIndex(result.StepInfo), len(result.AttachmentPaths))
475+
for _, pth := range result.AttachmentPaths {
476476
logger.Printf(" - %s", pth)
477477
}
478478
} else {

test/test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ type UploadResponse struct {
5050

5151
// Result ...
5252
type Result struct {
53-
Name string
54-
XMLContent []byte
55-
ImagePaths []string
56-
StepInfo models.TestResultStepInfo
53+
Name string
54+
XMLContent []byte
55+
AttachmentPaths []string
56+
StepInfo models.TestResultStepInfo
5757
}
5858

5959
// Results ...
@@ -95,7 +95,7 @@ func httpCall(apiToken, method, url string, input io.Reader, output interface{},
9595
return nil
9696
}
9797

98-
func findImages(testDir string) (imageFilePaths []string) {
98+
func findSupportedAttachments(testDir string) (imageFilePaths []string) {
9999
for _, ext := range testasset.AssetTypes {
100100
if paths, err := filepath.Glob(filepath.Join(testDir, "*"+ext)); err == nil {
101101
imageFilePaths = append(imageFilePaths, paths...)
@@ -227,15 +227,15 @@ func ParseTestResults(testsRootDir string, useLegacyXCResultExtractionMethod boo
227227
xmlData = append([]byte(`<?xml version="1.0" encoding="UTF-8"?>`+"\n"), xmlData...)
228228

229229
// so here I will have image paths, xml data, and step info per test dir in a bundle info
230-
images := findImages(testPhaseDirPath)
230+
attachments := findSupportedAttachments(testPhaseDirPath)
231231

232-
logger.Debugf("found images: %d", len(images))
232+
logger.Debugf("found attachments: %d", len(attachments))
233233

234234
results = append(results, Result{
235-
Name: testInfo.Name,
236-
XMLContent: xmlData,
237-
ImagePaths: images,
238-
StepInfo: *stepInfo,
235+
Name: testInfo.Name,
236+
XMLContent: xmlData,
237+
AttachmentPaths: attachments,
238+
StepInfo: *stepInfo,
239239
})
240240
}
241241
}
@@ -257,7 +257,7 @@ func (results Results) Upload(apiToken, endpointBaseURL, appSlug, buildSlug stri
257257
Name: result.Name,
258258
Step: result.StepInfo,
259259
}
260-
for _, asset := range result.ImagePaths {
260+
for _, asset := range result.AttachmentPaths {
261261
fi, err := os.Stat(asset)
262262
if err != nil {
263263
return fmt.Errorf("failed to get file info for %s: %w", asset, err)
@@ -286,7 +286,7 @@ func (results Results) Upload(apiToken, endpointBaseURL, appSlug, buildSlug stri
286286
}
287287

288288
for _, upload := range uploadResponse.Assets {
289-
for _, file := range result.ImagePaths {
289+
for _, file := range result.AttachmentPaths {
290290
if filepath.Base(file) == upload.FileName {
291291
fi, err := os.Open(file)
292292
if err != nil {

test/test_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path"
99
"path/filepath"
10+
"strings"
1011
"testing"
1112
"time"
1213

@@ -51,9 +52,9 @@ func Test_Upload(t *testing.T) {
5152

5253
results := Results{
5354
Result{
54-
XMLContent: testXMLContent,
55-
StepInfo: testStepInfo,
56-
ImagePaths: testAssetPaths,
55+
XMLContent: testXMLContent,
56+
StepInfo: testStepInfo,
57+
AttachmentPaths: testAssetPaths,
5758
},
5859
}
5960

@@ -218,7 +219,7 @@ func Test_ParseXctestResults(t *testing.T) {
218219
if err := createDummyFilesInDirWithContent(phaseDir, `{"name": "test name"}`, []string{"test-info.json"}); err != nil {
219220
t.Fatal("failed to create dummy files in dir, error:", err)
220221
}
221-
if err := createDummyFilesInDirWithContent(phaseDir, "test content", []string{"image.png", "image3.jpeg", "dirty.gif", "dirty.html"}); err != nil {
222+
if err := createDummyFilesInDirWithContent(phaseDir, "test content", []string{"image.png", "image3.jpeg", "dirty.gif", "dirty.html", "logs.txt", "zzz.log"}); err != nil {
222223
t.Fatal("failed to create dummy files in dir, error:", err)
223224
}
224225
if err := createDummyFilesInDirWithContent(phaseDir, sampleIOSXmlOutput, []string{"result.xml"}); err != nil {
@@ -234,6 +235,12 @@ func Test_ParseXctestResults(t *testing.T) {
234235
}
235236

236237
assert.Equal(t, sampleIOSXmlOutput, string(bundle[0].XMLContent))
238+
// Check if the attachments are correctly by the end of paths
239+
assert.Equal(t, 4, len(bundle[0].AttachmentPaths))
240+
assert.True(t, strings.HasSuffix(bundle[0].AttachmentPaths[0], "image3.jpeg"))
241+
assert.True(t, strings.HasSuffix(bundle[0].AttachmentPaths[1], "image.png"))
242+
assert.True(t, strings.HasSuffix(bundle[0].AttachmentPaths[2], "logs.txt"))
243+
assert.True(t, strings.HasSuffix(bundle[0].AttachmentPaths[3], "zzz.log"))
237244
}
238245

239246
// creating ios test results

test/testasset/testasset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"slices"
66
)
77

8-
var AssetTypes = []string{".jpg", ".jpeg", ".png"}
8+
var AssetTypes = []string{".jpg", ".jpeg", ".png", ".txt", ".log"}
99

1010
func IsSupportedAssetType(fileName string) bool {
1111
ext := filepath.Ext(fileName)

0 commit comments

Comments
 (0)