-
Notifications
You must be signed in to change notification settings - Fork 12
/
main_test.go
73 lines (67 loc) · 2.37 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"os"
"path/filepath"
"testing"
"github.com/bitrise-io/go-utils/pathutil"
)
func Test_tryExportTestAddonArtifact(t *testing.T) {
tmpDir, err := pathutil.NormalizedOSTempDirPath("")
if err != nil {
t.Fatal(err)
}
tests := []struct {
name string
artifactPth string
outputDir string
lastOtherDirIdx int
wantIdx int
wantOutputPth string
}{
{
name: "Exports Local Unit Test result XML file",
artifactPth: filepath.Join(tmpDir, "./app/build/test-results/testDebugUnitTest/TEST-sample.results.test.multiple.bitrise.com.multipletestresultssample.UnitTest0.xml"),
outputDir: filepath.Join(tmpDir, "1"),
lastOtherDirIdx: 0,
wantIdx: 0,
wantOutputPth: filepath.Join(tmpDir, "1", "app-debug", "TEST-sample.results.test.multiple.bitrise.com.multipletestresultssample.UnitTest0.xml"),
},
{
name: "Exports Jacoco result XML file",
artifactPth: filepath.Join(tmpDir, "./app/build/test-results/jacocoTestReleaseUnitTestReport/jacocoTestReleaseUnitTestReport.xml"),
outputDir: filepath.Join(tmpDir, "2"),
lastOtherDirIdx: 0,
wantIdx: 1,
wantOutputPth: filepath.Join(tmpDir, "2", "other-1", "jacocoTestReleaseUnitTestReport.xml"),
},
{
name: "Exports Other XML file",
artifactPth: filepath.Join(tmpDir, "./app/build/test-results/TEST-sample.results.test.multiple.bitrise.com.multipletestresultssample.UnitTest0.xml"),
outputDir: filepath.Join(tmpDir, "3"),
lastOtherDirIdx: 0,
wantIdx: 1,
wantOutputPth: filepath.Join(tmpDir, "3", "other-1", "TEST-sample.results.test.multiple.bitrise.com.multipletestresultssample.UnitTest0.xml"),
},
}
for _, tt := range tests {
dir := filepath.Dir(tt.artifactPth)
if err := os.MkdirAll(dir, 0700); err != nil {
t.Error(err)
continue
}
if _, err := os.Create(tt.artifactPth); err != nil {
t.Error(err)
continue
}
t.Run(tt.name, func(t *testing.T) {
if got := tryExportTestAddonArtifact(tt.artifactPth, tt.outputDir, tt.lastOtherDirIdx); got != tt.wantIdx {
t.Errorf("tryExportTestAddonArtifact() = %v, want %v", got, tt.wantIdx)
}
if exist, err := pathutil.IsPathExists(tt.wantOutputPth); err != nil {
t.Error(err)
} else if !exist {
t.Errorf("expected output file (%s) does not exist", tt.wantOutputPth)
}
})
}
}