Skip to content

Commit

Permalink
Merge pull request #15 from bitrise-steplib/quickfix-index-out-of-bou…
Browse files Browse the repository at this point in the history
…nds-error

Quickfix index out of bounds error
  • Loading branch information
lszucs authored May 31, 2019
2 parents 55470cf + 20b7d9c commit 428918d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Configs struct {
Module string `env:"module"`
Arguments string `env:"arguments"`
CacheLevel string `env:"cache_level,opt[none,only_deps,all]"`
IsDebug bool `env:"is_debug,opt[true,false]"`
}

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

if config.IsDebug {
log.SetEnableDebugLog(true)
log.Debugf("Debug mode enabled")
}

if err := stepconf.Parse(&config); err != nil {
failf("Couldn't create step config: %v\n", err)
}
Expand Down
10 changes: 10 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ inputs:
- "all"
- "only_deps"
- "none"
- is_debug: "false"
opts:
category: Debug
title: "Enable Debug Mode"
summary: The step will print more verbose logs if enabled.
description: The step will print more verbose logs if enabled.
is_required: true
value_options:
- "false"
- "true"
11 changes: 10 additions & 1 deletion testaddon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
"fmt"
"strings"
"unicode"

"github.com/bitrise-io/go-utils/log"
)

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

runes := []rune(variant)

if len(runes) == 0 {
return "", fmt.Errorf("get variant name from task name: empty string after trimming")
}
runes[0] = unicode.ToLower(runes[0])
variant = string(runes)

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

return module + "-" + variant, nil
log.Debugf("getUniqueDir(%s): (%s,%v)", path, ret, nil)
return ret, nil
}
35 changes: 35 additions & 0 deletions testaddon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"testing"
)

func TestGetUniqueDir(t *testing.T) {
tc := []struct{
title string
path string
wantStr string
isErr bool
}{
{
title: "should return error on empty string",
path: "",
wantStr: "",
isErr: true,
},
{
title: "should return error if artifact path ends in test results folder with trailing slash",
path: "/path/to/test-results/",
wantStr: "",
isErr: true,
},
}

for _, tt := range tc {
str, err := getUniqueDir(tt.path)
if str != tt.wantStr || (err != nil) != tt.isErr {
t.Fatalf("%s: got (%s, %s)", tt.title, str, err)
}
}

}

0 comments on commit 428918d

Please sign in to comment.