Commit eb1181ad authored by Lucas Jenss's avatar Lucas Jenss

Fix files configured in "cache" never being archived

When `archiveFiles`, part of BashShell, is passed
the configuration for the cache (coming from
`.gitlab-ci.yml`, it is expected to be of type
`map[string]interface{}`. The actual type coming in
from the YAML parser is `map[interface{}]interface{}`.
As a result, the type assertion never holds and thus
files are never archived during build.
parent 7e5e079f
......@@ -40,3 +40,22 @@ func ToTOML(src interface{}) string {
return data.String()
}
func ToConfigMap(list interface{}) (map[string]interface{}, bool) {
x, ok := list.(map[string]interface{})
if ok {
return x, ok
}
y, ok := list.(map[interface{}]interface{})
if !ok {
return nil, false
}
result := make(map[string]interface{})
for k, v := range y {
result[k.(string)] = v
}
return result, true
}
package helpers
import (
"gopkg.in/yaml.v1"
"reflect"
"testing"
)
......@@ -47,3 +49,42 @@ func TestSimpleTomlMarshalling(t *testing.T) {
t.Error("Expected ", expectedToml, ", got ", tomlString)
}
}
func TestToConfigMap(t *testing.T) {
data := `
build:
script:
- echo "1" >> foo
- cat foo
cache:
untracked: true
paths:
- vendor/
- foo
test:
script:
- make test
`
config := make(map[string]interface{})
err := yaml.Unmarshal([]byte(data), config)
if err != nil {
t.Error("Error parsing test YAML data")
}
expectedCacheConfig := map[string]interface{}{
"untracked": true,
"paths": []interface{}{"vendor/", "foo"},
}
cacheConfig, ok := ToConfigMap(config["cache"])
if !ok {
t.Error("Conversion failed")
}
if !reflect.DeepEqual(cacheConfig, expectedCacheConfig) {
t.Error("Result ", cacheConfig, " was not equal to ", expectedCacheConfig)
}
}
......@@ -211,7 +211,7 @@ func (b *BashShell) generateCommands(info common.ShellScriptInfo) string {
}
func (b *BashShell) archiveFiles(w io.Writer, list interface{}, runnerCommand, archiveType, archivePath string) {
hash, ok := list.(map[string]interface{})
hash, ok := helpers.ToConfigMap(list)
if !ok {
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment