Skip to content

Commit

Permalink
Merge pull request #948 from aziontech/dev
Browse files Browse the repository at this point in the history
Deploy to Production - 2024/9/10
  • Loading branch information
PatrickMenoti authored Sep 11, 2024
2 parents 62eabfe + 2717324 commit 0eb93f7
Show file tree
Hide file tree
Showing 11 changed files with 1,022 additions and 51 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/machinebox/graphql v0.2.2
github.com/manifoldco/promptui v0.9.0
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.2.2
github.com/pelletier/go-toml/v2 v2.2.3
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/schollz/progressbar/v3 v3.14.6
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -263,16 +263,10 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewBuildCmd(f *cmdutil.Factory) *BuildCmd {
}
}

func (cmd *BuildCmd) ExternalRun(fields *contracts.BuildInfo, confPath string, msgs *[]string) error {
func (b *BuildCmd) ExternalRun(fields *contracts.BuildInfo, confPath string, msgs *[]string) error {
fields.ProjectPath = confPath
return cmd.run(fields, msgs)
return b.run(fields, msgs)
}
132 changes: 132 additions & 0 deletions pkg/cmd/build/build_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package build

import (
"io"
"io/fs"
"testing"

"github.com/aziontech/azion-cli/pkg/cmdutil"
"github.com/aziontech/azion-cli/pkg/contracts"
"github.com/aziontech/azion-cli/pkg/iostreams"
"github.com/aziontech/azion-cli/pkg/logger"
"go.uber.org/zap/zapcore"
)

func TestNewCmd(t *testing.T) {
f := &cmdutil.Factory{
Flags: cmdutil.Flags{
GlobalFlagAll: false,
Format: "",
Out: "",
NoColor: false,
},
IOStreams: iostreams.System(),
}
NewCmd(f)
}

func TestBuildCmd_ExternalRun(t *testing.T) {
logger.New(zapcore.DebugLevel)

type fields struct {
Io *iostreams.IOStreams
WriteFile func(filename string, data []byte, perm fs.FileMode) error
CommandRunnerStream func(out io.Writer, cmd string, envvars []string) error
CommandRunInteractive func(f *cmdutil.Factory, comm string) error
CommandRunner func(f *cmdutil.Factory, comm string, envVars []string) (string, error)
FileReader func(path string) ([]byte, error)
GetAzionJsonContent func(pathConf string) (*contracts.AzionApplicationOptions, error)
WriteAzionJsonContent func(conf *contracts.AzionApplicationOptions, confPath string) error
EnvLoader func(path string) ([]string, error)
Stat func(path string) (fs.FileInfo, error)
GetWorkDir func() (string, error)
f *cmdutil.Factory
}
type args struct {
fields *contracts.BuildInfo
confPath string
msgs *[]string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "flow completed with success",
fields: fields{
GetAzionJsonContent: func(pathConf string) (*contracts.AzionApplicationOptions, error) {
return &contracts.AzionApplicationOptions{}, nil
},
Io: iostreams.System(),
CommandRunner: func(
f *cmdutil.Factory,
comm string,
envVars []string,
) (string, error) {
return "", nil
},
CommandRunInteractive: func(f *cmdutil.Factory, comm string) error {
return nil
},
WriteAzionJsonContent: func(
conf *contracts.AzionApplicationOptions,
confPath string,
) error {
return nil
},
f: &cmdutil.Factory{
Flags: cmdutil.Flags{
GlobalFlagAll: false,
Format: "",
Out: "",
NoColor: false,
},
IOStreams: iostreams.System(),
},
},
args: args{
fields: &contracts.BuildInfo{
ProjectPath: "",
},
confPath: "",
msgs: &[]string{},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
b := &BuildCmd{
Io: tt.fields.Io,
WriteFile: tt.fields.WriteFile,
CommandRunnerStream: tt.fields.CommandRunnerStream,
CommandRunInteractive: tt.fields.CommandRunInteractive,
CommandRunner: tt.fields.CommandRunner,
FileReader: tt.fields.FileReader,
GetAzionJsonContent: tt.fields.GetAzionJsonContent,
WriteAzionJsonContent: tt.fields.WriteAzionJsonContent,
EnvLoader: tt.fields.EnvLoader,
Stat: tt.fields.Stat,
GetWorkDir: tt.fields.GetWorkDir,
f: tt.fields.f,
}
if err := b.ExternalRun(tt.args.fields, tt.args.confPath, tt.args.msgs); (err != nil) != tt.wantErr {
t.Errorf("BuildCmd.ExternalRun() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestNewBuildCmd(t *testing.T) {
f := &cmdutil.Factory{
Flags: cmdutil.Flags{
GlobalFlagAll: false,
Format: "",
Out: "",
NoColor: false,
},
IOStreams: iostreams.System(),
}
NewBuildCmd(f)
}
18 changes: 5 additions & 13 deletions pkg/cmd/build/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@ import (
msg "github.com/aziontech/azion-cli/messages/build"
"github.com/aziontech/azion-cli/pkg/contracts"
"github.com/aziontech/azion-cli/pkg/logger"
vulcanPkg "github.com/aziontech/azion-cli/pkg/vulcan"
"go.uber.org/zap"
)

func (cmd *BuildCmd) run(fields *contracts.BuildInfo, msgs *[]string) error {
func (b *BuildCmd) run(fields *contracts.BuildInfo, msgs *[]string) error {
logger.Debug("Running build command")

err := RunBuildCmdLine(cmd, fields, msgs)
if err != nil {
return err
}

return nil
}

func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo, msgs *[]string) error {
var err error

conf, err := cmd.GetAzionJsonContent(fields.ProjectPath)
conf, err := b.GetAzionJsonContent(fields.ProjectPath)
if err != nil {
logger.Debug("Error while building your project", zap.Error(err))
return msg.ErrorBuilding
Expand Down Expand Up @@ -66,6 +58,6 @@ func RunBuildCmdLine(cmd *BuildCmd, fields *contracts.BuildInfo, msgs *[]string)
vulcanParams += " --firewall "
}

return vulcan(cmd, conf, vulcanParams, fields, msgs)

vul := vulcanPkg.NewVulcan()
return b.vulcan(vul, conf, vulcanParams, fields, msgs)
}
Loading

0 comments on commit 0eb93f7

Please sign in to comment.