Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set name in azin/azion.json on command init static #377

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/cmd/edge_applications/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio
case "cdn":
return initCdn(cmd, path, info)
case "static":
return initStatic(cmd, info)
return initStatic(cmd, info, options)
}

bytePackageJson, pathPackageJson, err := ReadPackageJson(cmd, path)
Expand Down Expand Up @@ -564,7 +564,7 @@ func initCdn(cmd *InitCmd, path string, info *InitInfo) error {
return nil
}

func initStatic(cmd *InitCmd, info *InitInfo) error {
func initStatic(cmd *InitCmd, info *InitInfo, options *contracts.AzionApplicationOptions) error {
shouldFetchTemplates, err := shouldFetch(cmd, info)
if err != nil {
return err
Expand All @@ -575,6 +575,10 @@ func initStatic(cmd *InitCmd, info *InitInfo) error {
return err
}

if err = cmd.organizeJsonFile(options, info); err != nil {
return err
}

fmt.Fprintf(cmd.Io.Out, fmt.Sprintf(msg.EdgeApplicationsInitSuccessful+"\n", info.Name)) // nolint:all
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/edge_applications/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func TestCobraCmd(t *testing.T) {
return nil, os.ErrNotExist
}

initCmd.FileReader = func(path string) ([]byte, error) {
return []byte("{\n \"name\": \"__DEFAULT__\",\n \"env\": \"production\",\n \"type\": \"static\",\n \"version-id\": \"\",\n \"domain\": {\n \"id\": 0,\n \"name\": \"__DEFAULT__\"\n },\n \"application\": {\n \"id\": 0,\n \"name\": \"__DEFAULT__\"\n },\n \"origin\": {\n \"name\": \"__DEFAULT__\",\n \"address\": [\"\"]\n},\n \"function\": {\n \"id\": 0,\n \"name\": \"__DEFAULT__\",\n \"file\": \"\",\n \"args\": \"\"\n }\n}"), nil
}

initCmd.WriteFile = func(filename string, data []byte, perm fs.FileMode) error {
return nil
}

cmd := NewCobraCmd(initCmd)

cmd.SetArgs([]string{"--name", "SUUPA_DOOPA", "--type", "static", "-y"})
Expand Down