created test case for go.mod

This commit is contained in:
2021-08-28 21:54:09 +04:00
parent 8fd9ccfa2d
commit 5c2b36c086
2 changed files with 25 additions and 2 deletions

View File

@@ -107,7 +107,7 @@ func (a *NewProject)CreateGoMod() error {
// Create new go.mod in the appropriate directory
cmd := exec.Command("go","mod","init",a.Module)
cmd.Dir = a.NewDir
if err := cmd.Start(); err != nil {
if err := cmd.Run(); err != nil {
return err
}
return nil

View File

@@ -29,7 +29,7 @@ func TestGenerateNewProject(t *testing.T) {
// Testing AST function to ensure imports are
// working as intended
func TestChangingImportAST(t *testing.T) {
// Create a new variable of type
// Create a new variable of type NewProject
var np NewProject
// Get current directory
path, err := config.GetCurrentPath()
@@ -66,4 +66,27 @@ func TestChangingImportAST(t *testing.T) {
t.Error(err)
}
}
// Testing the if Go Mod is created
func TestNewProject_CreateGoMod(t *testing.T) {
// Create a new variable of type NewProject
var np NewProject
path, err := config.GetCurrentPath()
if err != nil {
fmt.Println(err)
t.Error(err)
}
// Set new project name as Test
np.Name = "Test"
// Set new project module as github.com/Test
np.Module = "github.com/Test"
// Set Path of the new project
np.NewDir = path + "Test/"
// Creating a go.mod file
err = np.CreateGoMod()
if err != nil {
fmt.Println(err)
t.Error(err)
}
}