blob: 9079ef3ba9f9250dbdc8c8420aa645a069b06df5 [file] [log] [blame]
package unittest
import (
"path/filepath"
"strings"
)
const templatePrefix string = "templates"
const subchartPrefix string = "charts"
// getTemplateFileName,
// Validate if prefix templates is not there,
// used for backward compatibility of old unittests.
func getTemplateFileName(fileName string) string {
if !strings.HasPrefix(fileName, templatePrefix) && !strings.HasPrefix(fileName, subchartPrefix) {
// Within templates unix separators are always used.
return filepath.ToSlash(filepath.Join(templatePrefix, fileName))
}
return fileName
}
func spliteChartRoutes(routePath string) []string {
splited := strings.Split(routePath, string(filepath.Separator))
routes := make([]string, len(splited)/2+1)
for r := 0; r < len(routes); r++ {
routes[r] = splited[r*2]
}
return routes
}
func scopeValuesWithRoutes(routes []string, values map[interface{}]interface{}) map[interface{}]interface{} {
if len(routes) > 1 {
return scopeValuesWithRoutes(
routes[:len(routes)-1],
map[interface{}]interface{}{
routes[len(routes)-1]: values,
},
)
}
return values
}