func InstallTestDeps() error {
	cmd := exec.Command("go", "get", "github.com/golang/mock/gomock")
	err := cmd.Run()
	if err != nil {
		return err
	}
	cmd = exec.Command("go", "get", "github.com/golang/mock/mockgen")
	return cmd.Run()
}
Install test dependencies like gomock/mockgen
package main
import (
	"context"
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"github.com/magefile/mage/mg"  
	"github.com/magefile/mage/sh"
)
const (
	BasePackage = "github.com/Scalingo/sand"
)
var Default = Build
func Build(ctx context.Context) error {
	mg.CtxDeps(ctx, InstallDeps)
	fmt.Println("Building…")
	cmd := exec.Command("go", "build", "-i", "github.com/Scalingo/sand/cmd/sand-agent")
	return cmd.Run()
}
func Test(ctx context.Context) error {
	fmt.Println("Testing…")
	return sh.RunV("go", "test", "./...")
}
func GenerateMocks(ctx context.Context) error {
	mg.CtxDeps(ctx, InstallTestDeps)
	mocks := []struct {
		Package   string
		Interface string
	}{
		{Package: "netlink", Interface: "Handler"},
		{Package: "ipallocator", Interface: "IPAllocator"},
		{Package: "netnsbuilder", Interface: "Manager"},
		{Package: "idmanager", Interface: "Manager"},
		{Package: "store", Interface: "Store"},
		{Package: "store", Interface: "Watcher"},
		{Package: "endpoint", Interface: "Repository"},
		{Package: "network", Interface: "Repository"},
		{Package: "network/netmanager", Interface: "NetManager"},
		{Package: "network/overlay", Interface: "NetworkEndpointListener"},
		{Package: "client/sand", Interface: "Client"},
	}
	for _, mock := range mocks {
		fmt.Printf("Building mock of %v#%v\n", mock.Package, mock.Interface)
		mockPackage := mock.Package + "mock"
		mockDirectory := fmt.Sprintf("test/mocks/%s", mockPackage)
		filePackage := filepath.Base(mockPackage)
		mockFile := fmt.Sprintf("%s/%s_mock.go", mockDirectory, strings.ToLower(mock.Interface))
		err := os.MkdirAll(mockDirectory, 0755)
		if err != nil {
			return err
		}
		err = sh.Run(
			"mockgen",
			"-destination", mockFile,
			"-package", filePackage,
			fmt.Sprintf("%s/%s", BasePackage, mock.Package),
			mock.Interface,
		)
		if err != nil {
			return err
		}
		err = sh.Run("sed", "-i", fmt.Sprintf("s,%s/vendor/,,", BasePackage), mockFile)
		if err != nil {
			return err
		}
		err = sh.RunV("goimports", "-w", mockFile)
		if err != nil {
			return err
		}
	}
	return nil
}
func Install(ctx context.Context) error {
	mg.CtxDeps(ctx, Build)
	fmt.Println("Installing…")
	return sh.Run("go", "install", "github.com/Scalingo/sand/cmd/sand-agent")
}
func InstallDeps() error {
	return nil
}