Skip to content

Commit

Permalink
template pull - disallow function creation when 'template.yml'
Browse files Browse the repository at this point in the history
is not present in language template directory

Needs to add a 'template.yml' to each fake language template dir in
commands/testdata/new_function/template/<lang> in order to have current
tests pass. Deletes some unnecessary .gitignore files as a result.

Signed-off-by: Eric Stoekl <ems5311@gmail.com>
  • Loading branch information
ericstoekl committed Nov 9, 2017
1 parent 85b2a1c commit d77e292
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 4 deletions.
8 changes: 7 additions & 1 deletion commands/new_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const ListOptionOutput = `Languages available as templates:
- python3
- ruby`

const LangNotExistsOutput = `(?m:bash is unavailable or not supported.)`
const LangNotExistsOutput = `(?m:is unavailable or not supported.)`

type NewFunctionTest struct {
title string
Expand All @@ -52,6 +52,12 @@ var NewFunctionTests = []NewFunctionTest{
funcLang: "dockerfile",
expectedMsg: SuccessMsg,
},
{
title: "invalid_1",
funcName: "new-test-invalid-1",
funcLang: "dockerfilee",
expectedMsg: LangNotExistsOutput,
},
}

func runNewFunctionTest(t *testing.T, nft NewFunctionTest) {
Expand Down
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/csharp/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: csharp
fprocess: dotnet ./root.dll
Empty file.
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/go-armhf/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: go-armhf
fprocess: ./handler
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/go/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: go
fprocess: ./handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: node-arm64
fprocess: node index.js
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: node-armhf
fprocess: node index.js
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/node/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: node
fprocess: node index.js
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: python-armhf
fprocess: python index.py
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/python/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: python
fprocess: python index.py
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/python3/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: python3
fprocess: python3 index.py
2 changes: 2 additions & 0 deletions commands/testdata/new_function/template/ruby/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: ruby
fprocess: ruby index.rb
7 changes: 6 additions & 1 deletion stack/language_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func IsValidTemplate(lang string) bool {
if strings.ToLower(lang) == "dockerfile" {
found = true
} else if _, err := os.Stat("./template/" + lang); err == nil {
found = true
templateYAMLPath := "./template/" + lang + "/template.yml"

_, err := ParseYAMLForLanguageTemplate(templateYAMLPath)
if err == nil {
found = true
}
}

return found
Expand Down
4 changes: 2 additions & 2 deletions stack/language_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Test_IsValidTemplate(t *testing.T) {
defer func() {
os.RemoveAll("template")
}()
if !IsValidTemplate("python") {
t.Fatalf("python must be valid")
if IsValidTemplate("python") {
t.Fatalf("python must is not valid because it does not contain template.yml")
}
}

0 comments on commit d77e292

Please sign in to comment.