mirror of
https://github.com/harness/drone.git
synced 2025-05-21 19:39:59 +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"
|
"errors"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
templating "text/template"
|
templating "text/template"
|
||||||
|
|
||||||
"github.com/drone/drone/core"
|
"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) {
|
func (p *templatePlugin) Convert(ctx context.Context, req *core.ConvertArgs) (*core.Config, error) {
|
||||||
// check type is yaml
|
// 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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ package converter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"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) {
|
func TestTemplatePluginConvertTemplateNotFound(t *testing.T) {
|
||||||
templateArgs, err := ioutil.ReadFile("testdata/starlark.template.yml")
|
templateArgs, err := ioutil.ReadFile("testdata/starlark.template.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user