Skip to content

Commit 428918d

Browse files
authored
Merge pull request bitrise-steplib#15 from bitrise-steplib/quickfix-index-out-of-bounds-error
Quickfix index out of bounds error
2 parents 55470cf + 20b7d9c commit 428918d

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

main.go

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Configs struct {
2828
Module string `env:"module"`
2929
Arguments string `env:"arguments"`
3030
CacheLevel string `env:"cache_level,opt[none,only_deps,all]"`
31+
IsDebug bool `env:"is_debug,opt[true,false]"`
3132
}
3233

3334
func failf(f string, args ...interface{}) {
@@ -112,6 +113,11 @@ func filterVariants(module, variant string, variantsMap gradle.Variants) (gradle
112113
func main() {
113114
var config Configs
114115

116+
if config.IsDebug {
117+
log.SetEnableDebugLog(true)
118+
log.Debugf("Debug mode enabled")
119+
}
120+
115121
if err := stepconf.Parse(&config); err != nil {
116122
failf("Couldn't create step config: %v\n", err)
117123
}

step.yml

+10
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,13 @@ inputs:
8080
- "all"
8181
- "only_deps"
8282
- "none"
83+
- is_debug: "false"
84+
opts:
85+
category: Debug
86+
title: "Enable Debug Mode"
87+
summary: The step will print more verbose logs if enabled.
88+
description: The step will print more verbose logs if enabled.
89+
is_required: true
90+
value_options:
91+
- "false"
92+
- "true"

testaddon.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import (
44
"fmt"
55
"strings"
66
"unicode"
7+
8+
"github.com/bitrise-io/go-utils/log"
79
)
810

911
// getUniqueDir returns the unique subdirectory inside the test addon export diroctory for a given artifact.
1012
func getUniqueDir(path string) (string, error) {
13+
log.Debugf("getUniqueDir(%s)", path)
1114
parts := strings.Split(path, "/")
1215
i := len(parts) - 1
1316
for i > 0 && parts[i] != "test-results" {
@@ -27,13 +30,19 @@ func getUniqueDir(path string) (string, error) {
2730
variant = strings.TrimSuffix(variant, "UnitTest")
2831

2932
runes := []rune(variant)
33+
34+
if len(runes) == 0 {
35+
return "", fmt.Errorf("get variant name from task name: empty string after trimming")
36+
}
3037
runes[0] = unicode.ToLower(runes[0])
3138
variant = string(runes)
3239

3340
if i < 2 {
3441
return "", fmt.Errorf("get module name: out of index error")
3542
}
3643
module := parts[i-2]
44+
ret := module + "-" + variant
3745

38-
return module + "-" + variant, nil
46+
log.Debugf("getUniqueDir(%s): (%s,%v)", path, ret, nil)
47+
return ret, nil
3948
}

testaddon_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestGetUniqueDir(t *testing.T) {
8+
tc := []struct{
9+
title string
10+
path string
11+
wantStr string
12+
isErr bool
13+
}{
14+
{
15+
title: "should return error on empty string",
16+
path: "",
17+
wantStr: "",
18+
isErr: true,
19+
},
20+
{
21+
title: "should return error if artifact path ends in test results folder with trailing slash",
22+
path: "/path/to/test-results/",
23+
wantStr: "",
24+
isErr: true,
25+
},
26+
}
27+
28+
for _, tt := range tc {
29+
str, err := getUniqueDir(tt.path)
30+
if str != tt.wantStr || (err != nil) != tt.isErr {
31+
t.Fatalf("%s: got (%s, %s)", tt.title, str, err)
32+
}
33+
}
34+
35+
}

0 commit comments

Comments
 (0)