created test case for go.mod
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user