Skip to content

Commit

Permalink
FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Aug 27, 2018
1 parent 8711a71 commit bf9e226
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 67 deletions.
25 changes: 2 additions & 23 deletions mesg/deploy_deployer.go
Expand Up @@ -4,17 +4,15 @@ import (
"fmt"
"io"
"io/ioutil"
"net/url"
"os"

"github.com/docker/docker/pkg/archive"
"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/database/services"
"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/x/xgit"
uuid "github.com/satori/go.uuid"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
)

type serviceDeployer struct {
Expand Down Expand Up @@ -53,7 +51,7 @@ func (d *serviceDeployer) FromGitURL(url string) (*service.Service, *importer.Va
if err != nil {
return nil, nil, err
}
if err := d.gitClone(url, path); err != nil {
if err := xgit.Clone(url, path); err != nil {
return nil, nil, err
}
d.sendStatus(fmt.Sprintf("%s Service downloaded with success.", aurora.Green("✔")), DONE)
Expand All @@ -76,25 +74,6 @@ func (d *serviceDeployer) FromGzippedTar(r io.Reader) (*service.Service, *import
return d.deploy(path)
}

// gitClone clones a repo hosted at repoURL to path.
func (d *serviceDeployer) gitClone(repoURL string, path string) error {
u, err := url.Parse(repoURL)
if err != nil {
return err
}
if u.Scheme == "" {
u.Scheme = "https"
}
options := &git.CloneOptions{}
if u.Fragment != "" {
options.ReferenceName = plumbing.ReferenceName("refs/heads/" + u.Fragment)
u.Fragment = ""
}
options.URL = u.String()
_, err = git.PlainClone(path, false, options)
return err
}

// deploy deploys a service in path.
func (d *serviceDeployer) deploy(path string) (*service.Service, *importer.ValidationError, error) {
defer os.RemoveAll(path)
Expand Down
37 changes: 0 additions & 37 deletions mesg/deploy_deployer_test.go
Expand Up @@ -6,45 +6,8 @@ import (

"github.com/mesg-foundation/core/service"
"github.com/stretchr/testify/require"
git "gopkg.in/src-d/go-git.v4"
)

func TestGitCloneRepositoryDoNotExist(t *testing.T) {
m, _ := newMESGAndDockerTest(t)
deployer := newServiceDeployer(m)

path, _ := deployer.createTempDir()
defer os.RemoveAll(path)
err := deployer.gitClone("/doNotExist", path)
require.NotNil(t, err)
}

func TestGitCloneWithoutURLSchema(t *testing.T) {
m, _ := newMESGAndDockerTest(t)
deployer := newServiceDeployer(m)

path, _ := deployer.createTempDir()
defer os.RemoveAll(path)
err := deployer.gitClone("github.com/mesg-foundation/awesome.git", path)
require.Nil(t, err)
}

func TestGitCloneCustomBranch(t *testing.T) {
m, _ := newMESGAndDockerTest(t)
deployer := newServiceDeployer(m)

branchName := "5-generic-service"
path, _ := deployer.createTempDir()
defer os.RemoveAll(path)
err := deployer.gitClone("github.com/mesg-foundation/service-ethereum-erc20#"+branchName, path)
require.Nil(t, err)
repo, err := git.PlainOpen(path)
require.Nil(t, err)
branch, err := repo.Branch(branchName)
require.Nil(t, err)
require.NotNil(t, branch)
}

func TestCreateTempFolder(t *testing.T) {
m, _ := newMESGAndDockerTest(t)
deployer := newServiceDeployer(m)
Expand Down
10 changes: 3 additions & 7 deletions mesg/deploy_test.go
Expand Up @@ -8,9 +8,9 @@ import (
"testing"

"github.com/cnf/structhash"
"github.com/docker/docker/pkg/archive"
"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/x/xdocker/xarchive"
"github.com/stretchr/testify/require"
)

Expand All @@ -27,9 +27,7 @@ func TestDeployService(t *testing.T) {
go func() {
defer wg.Done()

archive, err := archive.TarWithOptions(path, &archive.TarOptions{
Compression: archive.Gzip,
})
archive, err := xarchive.GzippedTar(path)
require.Nil(t, err)

service, validationError, err := mesg.DeployService(archive, DeployServiceStatusOption(statuses))
Expand Down Expand Up @@ -74,9 +72,7 @@ func TestDeployInvalidService(t *testing.T) {
go func() {
defer wg.Done()

archive, err := archive.TarWithOptions(path, &archive.TarOptions{
Compression: archive.Gzip,
})
archive, err := xarchive.GzippedTar(path)
require.Nil(t, err)

service, validationError, err := mesg.DeployService(archive, DeployServiceStatusOption(statuses))
Expand Down

0 comments on commit bf9e226

Please sign in to comment.