Skip to content

Commit

Permalink
feat: ajusted testing in build and init and remove testing flareact
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwelbm committed May 8, 2023
1 parent 27d658c commit e1bf538
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 289 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/fatih/color v1.13.0
github.com/go-faker/faker/v4 v4.1.0
github.com/go-git/go-git/v5 v5.4.2
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.14.0
github.com/tidwall/gjson v1.14.3
github.com/tidwall/sjson v1.2.5
Expand All @@ -17,7 +17,7 @@ require (
require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/golang/protobuf v1.5.2 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
Expand Down Expand Up @@ -551,6 +553,8 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
8 changes: 1 addition & 7 deletions pkg/cmd/edge_applications/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func RunBuildCmdLine(cmd *BuildCmd, path string) error {
}

switch typeLang.String() {
case "nextjs", "flareact":
case "nextjs":

//pre-build version id. Used to check if there were changes to the project
verID, err := cmd.VersionId(path)
Expand All @@ -151,12 +151,6 @@ func RunBuildCmdLine(cmd *BuildCmd, path string) error {
return utils.ErrorWritingAzionJsonFile
}

case "javascript":
err := runCommand(cmd, conf)
if err != nil {
return err
}

default:
return utils.ErrorUnsupportedType
}
Expand Down
84 changes: 0 additions & 84 deletions pkg/cmd/edge_applications/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package build

import (
"bytes"
"errors"
"io"
"io/fs"
"os"
"testing"

Expand All @@ -16,87 +13,6 @@ import (
)

func TestBuild(t *testing.T) {
t.Run("basic", func(t *testing.T) {
f, stdout, _ := testutils.NewFactory(nil)

jsonContent := bytes.NewBufferString(`
{
"build": {
"cmd": "npm run build",
"output-ctrl": "on-error"
},
"type": "javascript"
}
`)

envVars := []string{"VAR1=PAODEBATATA", "VAR2=PAODEQUEIJO"}

command := newBuildCmd(f)

command.FileReader = func(path string) ([]byte, error) {
return jsonContent.Bytes(), nil
}

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

command.VersionId = func(dir string) (string, error) {
return "123456789", nil
}

command.Stat = func(path string) (fs.FileInfo, error) {
return nil, nil
}

command.CommandRunner = func(cmd string, envs []string) (string, int, error) {
return "Build completed", 0, nil
}
command.EnvLoader = func(path string) ([]string, error) {
return envVars, nil
}

err := command.run()
require.NoError(t, err)

require.Contains(t, stdout.String(), `Your Edge Application was built successfully`)
})

t.Run("cmd failed", func(t *testing.T) {
f, stdout, _ := testutils.NewFactory(nil)

jsonContent := bytes.NewBufferString(`
{
"build": {
"cmd": "npm run build",
"output-ctrl": "disable"
},
"type": "javascript"
}
`)

envVars := []string{"VAR1=PAODEBATATA", "VAR2=PAODEQUEIJO"}
expectedErr := errors.New("invalid file")

command := newBuildCmd(f)

command.FileReader = func(path string) ([]byte, error) {
return jsonContent.Bytes(), nil
}
command.CommandRunnerStream = func(out io.Writer, cmd string, envvars []string) error {
return expectedErr

}
command.EnvLoader = func(path string) ([]string, error) {
return envVars, nil
}

err := command.run()
require.Error(t, err, expectedErr)

require.Contains(t, stdout.String(), `Running build step command`)
})

t.Run("in build.cmd to run, type not informed", func(t *testing.T) {
f, _, _ := testutils.NewFactory(nil)

Expand Down
64 changes: 0 additions & 64 deletions pkg/cmd/edge_applications/edge_applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,70 +192,6 @@ func TestNewCmd(t *testing.T) {
},
},
},
{
// go test -run TestNewCmd/flow_success_full_flareact_init,_build_and_publih -v -cover
name: "flow success full flareact init, build and publih",
args: args{
init: func(f *cmdutil.Factory) *initcmd.InitCmd {
return &initcmd.InitCmd{
Io: f.IOStreams,
GetWorkDir: func() (string, error) { return "", nil },
FileReader: func(path string) ([]byte, error) {
return []byte(`{"init": {"cmd": "ls", "env": "./azion/init.env", "output-ctrl": "on-error"}, "type": "flareact"}`), nil
},
CommandRunner: func(cmd string, envvars []string) (string, int, error) { return "", 0, nil },
LookPath: func(bin string) (string, error) { return "", nil },
IsDirEmpty: func(dirpath string) (bool, error) { return true, nil },
CleanDir: func(dirpath string) error { return nil },
WriteFile: func(filename string, data []byte, perm fs.FileMode) error { return nil },
OpenFile: func(name string) (*os.File, error) { return nil, nil },
RemoveAll: func(path string) error { return nil },
Rename: func(oldpath, newpath string) error { return nil },
CreateTempDir: func(dir, pattern string) (string, error) { return "", nil },
EnvLoader: func(path string) ([]string, error) { return []string{}, nil },
Stat: func(path string) (fs.FileInfo, error) { return nil, nil },
Mkdir: func(path string, perm os.FileMode) error { return nil },
GitPlainClone: func(path string, isBare bool, o *git.CloneOptions) (*git.Repository, error) {
return &git.Repository{}, nil
},
}
},
build: func(f *cmdutil.Factory) *buildcmd.BuildCmd {
return &buildcmd.BuildCmd{
Io: f.IOStreams,
FileReader: func(path string) ([]byte, error) {
return []byte(`{"build": {"cmd": "./azion/webdev.sh build", "env": "./azion/init.env", "output-ctrl": "on-error"}, "type": "flareact"}`), nil
},
CommandRunner: func(cmd string, envs []string) (string, int, error) { return "Build completed", 0, nil },
ConfigRelativePath: "/azion/config.json",
GetWorkDir: func() (string, error) { return "", nil },
EnvLoader: func(path string) ([]string, error) { return []string{}, nil },
WriteFile: func(filename string, data []byte, perm fs.FileMode) error { return nil },
Stat: func(path string) (fs.FileInfo, error) { return nil, nil },
VersionId: func(dir string) (string, error) { return "123456789", nil },
}
},
publish: func(f *cmdutil.Factory) *publishcmd.PublishCmd {
return &publishcmd.PublishCmd{
Io: f.IOStreams,
Open: func(name string) (*os.File, error) { return nil, nil },
GetWorkDir: func() (string, error) { return "", nil },
FilepathWalk: func(root string, fn filepath.WalkFunc) error { return nil },
EnvLoader: func(path string) ([]string, error) { return []string{}, nil },
CommandRunner: func(cmd string, env []string) (string, int, error) { return "", 0, nil },
GetAzionJsonContent: func() (*contracts.AzionApplicationOptions, error) { return &contracts.AzionApplicationOptions{}, nil },
WriteAzionJsonContent: func(conf *contracts.AzionApplicationOptions) error { return nil },
FileReader: func(path string) ([]byte, error) {
return []byte(`{"publish": {"pre_cmd": "./azion/webdev.sh publish", "env": "./azion/init.env", "output-ctrl": "on-error"}, "type": "flareact"}`), nil
},
WriteFile: func(filename string, data []byte, perm fs.FileMode) error { return nil },
GetAzionJsonCdn: func() (*contracts.AzionApplicationCdn, error) {
return &contracts.AzionApplicationCdn{}, nil
},
}
},
},
},
}

for _, tt := range tests {
Expand Down
5 changes: 1 addition & 4 deletions pkg/cmd/edge_applications/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio
info.Name = filepath.Base(path)
fmt.Fprintf(cmd.Io.Out, "%s\n", msg.EdgeApplicationsInitNameNotSentStatic)
}

return initStatic(cmd, path, info)
}

Expand Down Expand Up @@ -227,7 +226,7 @@ func DetectedProjectJS(bytePackageJson []byte) (projectName string, projectSetti
projectName = packageJson.Name
projectSettings = "nextjs"
} else {
return "", "", msg.ErrorNotSupportTypeLang
return "", "", utils.ErrorUnsupportedType
}

return projectName, projectSettings, nil
Expand Down Expand Up @@ -575,8 +574,6 @@ func initStatic(cmd *InitCmd, path string, info *InitInfo) error {
options.Function.Name = "__DEFAULT__"
options.Application.Name = "__DEFAULT__"

fmt.Println("options ", options)

data, err := json.MarshalIndent(options, "", " ")
if err != nil {
return msg.ErrorUnmarshalAzionFile
Expand Down
Loading

0 comments on commit e1bf538

Please sign in to comment.