Skip to content

Commit

Permalink
Merge fc06bda into 9b5c4ff
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Jan 22, 2018
2 parents 9b5c4ff + fc06bda commit 6c73025
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func InitializeInertiaProject() error {
if err != nil {
return err
}
err = common.CheckForDockerCompose(cwd)
if err != nil {
return err
}

return createConfigDirectory()
}
Expand Down
16 changes: 16 additions & 0 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ func CheckForGit(cwd string) error {
return nil
}

// CheckForDockerCompose returns error if current directory is a
// not a docker-compose project
func CheckForDockerCompose(cwd string) error {
dockerComposeYML := filepath.Join(cwd, "docker-compose.yml")
dockerComposeYAML := filepath.Join(cwd, "docker-compose.yaml")
_, err := os.Stat(dockerComposeYML)
YMLpresent := os.IsNotExist(err)
_, err = os.Stat(dockerComposeYAML)
YAMLpresent := os.IsNotExist(err)
if YMLpresent && YAMLpresent {
return errors.New("this does not appear to be a docker-compose project - currently,\n" +
"Inertia only supports docker-compose projects.")
}
return nil
}

// GetLocalRepo gets the repo from disk.
func GetLocalRepo() (*git.Repository, error) {
cwd, err := os.Getwd()
Expand Down
22 changes: 22 additions & 0 deletions common/util_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

import (
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -24,3 +26,23 @@ func TestGetSSHRemoteURL(t *testing.T) {
assert.Equal(t, sshURL, GetSSHRemoteURL(httpsURL))
assert.Equal(t, sshURL, GetSSHRemoteURL(sshURL))
}

func TestCheckForGit(t *testing.T) {
cwd, _ := os.Getwd()
assert.NotEqual(t, nil, CheckForGit(cwd))
inertia := strings.TrimSuffix(cwd, "/common")
assert.Equal(t, nil, CheckForGit(inertia))
}

func TestCheckForDockerCompose(t *testing.T) {
cwd, _ := os.Getwd()
assert.NotEqual(t, nil, CheckForDockerCompose(cwd))
file, _ := os.Create(cwd + "/docker-compose.yml")
file.Close()
assert.Equal(t, nil, CheckForDockerCompose(cwd))
os.Remove(cwd + "/docker-compose.yml")
file, _ = os.Create(cwd + "/docker-compose.yaml")
file.Close()
assert.Equal(t, nil, CheckForDockerCompose(cwd))
os.Remove(cwd + "/docker-compose.yaml")
}

0 comments on commit 6c73025

Please sign in to comment.