mirror of
https://github.com/harness/drone.git
synced 2025-05-21 11:29:52 +08:00
Template converter, don't skip .yaml extension. (#3242)
This commit is contained in:
parent
3a23b0d0d4
commit
82a7b113ed
@ -23,7 +23,6 @@ import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
templating "text/template"
|
||||
|
||||
"github.com/drone/drone/core"
|
||||
@ -56,7 +55,9 @@ type templatePlugin struct {
|
||||
|
||||
func (p *templatePlugin) Convert(ctx context.Context, req *core.ConvertArgs) (*core.Config, error) {
|
||||
// check type is yaml
|
||||
if strings.HasSuffix(req.Repo.Config, ".yml") == false {
|
||||
configExt := filepath.Ext(req.Repo.Config)
|
||||
|
||||
if configExt != ".yml" && configExt != ".yaml" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ package converter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -141,6 +142,48 @@ func TestTemplatePluginConvertDroneFileTypePipeline(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test makes sure that we don't skip templating for neither the "yml" or "yaml" extension.
|
||||
func TestTemplatePluginConvertDroneFileYamlExtensions(t *testing.T) {
|
||||
extensions := []string{"yml", "yaml"}
|
||||
dummyErr := errors.New("dummy-error")
|
||||
|
||||
for _, extension := range extensions {
|
||||
t.Run(extension, func(t *testing.T) {
|
||||
args, err := ioutil.ReadFile("testdata/yaml.template.yml")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
controller := gomock.NewController(t)
|
||||
defer controller.Finish()
|
||||
|
||||
templates := mock.NewMockTemplateStore(controller)
|
||||
templates.EXPECT().FindName(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, dummyErr)
|
||||
|
||||
plugin := Template(templates, 0)
|
||||
req := &core.ConvertArgs{
|
||||
Build: &core.Build{
|
||||
After: "3d21ec53a331a6f037a91c368710b99387d012c1",
|
||||
},
|
||||
Repo: &core.Repository{
|
||||
Slug: "octocat/hello-world",
|
||||
Config: ".drone." + extension,
|
||||
},
|
||||
Config: &core.Config{Data: string(args)},
|
||||
}
|
||||
|
||||
_, err = plugin.Convert(noContext, req)
|
||||
if err != nil && err != dummyErr {
|
||||
t.Error(err)
|
||||
}
|
||||
if err == nil {
|
||||
t.Errorf("Templating was skipped")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTemplatePluginConvertTemplateNotFound(t *testing.T) {
|
||||
templateArgs, err := ioutil.ReadFile("testdata/starlark.template.yml")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user