Skip to content

Commit

Permalink
Fn init now respects the --name arg (#386)
Browse files Browse the repository at this point in the history
Previously the --name arg was ignored and the name of the
directory was being used as the name in all cases.

Fixes: #385
  • Loading branch information
Matthew Gilliard authored Aug 16, 2018
1 parent cfe0b20 commit 9a12306
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ func ValidateFuncName(name string) error {
func (a *initFnCmd) BuildFuncFile(c *cli.Context, path string) error {
var err error

if c.String("name") != "" {
a.ff.Name = strings.ToLower(c.String("name"))
}

if a.ff.Name == "" {
// then defaults to current directory for name, the name must be lowercase
a.ff.Name = strings.ToLower(filepath.Base(path))
Expand Down Expand Up @@ -445,6 +449,10 @@ func (a *initFnCmd) BuildFuncFile(c *cli.Context, path string) error {
func (a *initFnCmd) BuildFuncFileV20180707(c *cli.Context, path string) error {
var err error

if c.String("name") != "" {
a.ffV20180707.Name = strings.ToLower(c.String("name"))
}

if a.ffV20180707.Name == "" {
// then defaults to current directory for name, the name must be lowercase
a.ffV20180707.Name = strings.ToLower(filepath.Base(path))
Expand Down
26 changes: 26 additions & 0 deletions test/cli_init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package test

import (
"testing"

"github.com/fnproject/cli/testharness"
)

func TestSettingFuncName(t *testing.T) {
t.Run("`fn init --name` should set the name in func.yaml", func(t *testing.T) {
t.Parallel()
h := testharness.Create(t)
defer h.Cleanup()

funcName := h.NewFuncName()
dirName := funcName + "_dir"
h.Fn("init", "--runtime", "java", "--name", funcName, dirName).AssertSuccess()

h.Cd(dirName)

yamlFile := h.GetYamlFile("func.yaml")
if yamlFile.Name != funcName {
t.Fatalf("Name was not set to %s in func.yaml", funcName)
}
})
}

0 comments on commit 9a12306

Please sign in to comment.