Skip to content

Commit

Permalink
Add OS X CI Matrix support to Travis (thrasher-corp#284)
Browse files Browse the repository at this point in the history
Add OS X CI Matrix support to Travis
  • Loading branch information
shazbert authored and thrasher- committed Apr 30, 2019
1 parent 88bc17a commit 2f1405e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 91 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
matrix:
include:
- language: node_js
name: 'GoCryptoTrader [front-end]'
node_js:
- '10'
- '8'
Expand All @@ -15,6 +16,21 @@ matrix:

- language: go
dist: xenial
name: 'GoCryptoTrader [back-end] [linux]'
go:
- 1.12.x
env:
- GO111MODULE=on
install: true

script:
- make check
after_success:
- bash <(curl -s https://codecov.io/bash)

- language: go
os: osx
name: 'GoCryptoTrader [back-end] [darwin]'
go:
- 1.12.x
env:
Expand Down
19 changes: 13 additions & 6 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"os/user"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -605,13 +605,20 @@ func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error) {
// Linux/Unix or OSX - $HOME/.gocryptotrader
func GetDefaultDataDir(env string) string {
if env == "windows" {
return os.Getenv("APPDATA") + GetOSPathSlash() + "GoCryptoTrader"
return filepath.Join(os.Getenv("APPDATA"), "GoCryptoTrader")
}
dir, ok := os.LookupEnv("HOME")
if !ok {
return ""

usr, err := user.Current()
if err == nil {
return filepath.Join(usr.HomeDir, ".gocryptotrader")
}

dir, err := os.UserHomeDir()
if err != nil {
log.Warn("Environment variable unset, defaulting to current directory")
dir = "."
}
return path.Join(dir, ".gocryptotrader")
return filepath.Join(dir, ".gocryptotrader")
}

// CreateDir creates a directory based on the supplied parameter
Expand Down
113 changes: 42 additions & 71 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"bytes"
"net/url"
"os"
"path"
"os/user"
"path/filepath"
"reflect"
"runtime"
"strings"
Expand Down Expand Up @@ -961,17 +962,24 @@ func TestGetDefaultDataDir(t *testing.T) {
if !ok {
t.Fatal("APPDATA is not set")
}
dir += GetOSPathSlash() + "GoCryptoTrader"
actualOutput := GetDefaultDataDir("windows")
dir = filepath.Join(dir, "GoCryptoTrader")
actualOutput := GetDefaultDataDir(runtime.GOOS)
if actualOutput != dir {
t.Fatalf("Unexpected result. Got: %v Expected: %v", actualOutput, dir)
}
case "linux", "darwin":
dir, ok := os.LookupEnv("HOME")
if !ok {
t.Fatal("HOME is not set")
default:
var dir string
usr, err := user.Current()
if err == nil {
dir = usr.HomeDir
} else {
var err error
dir, err = os.UserHomeDir()
if err != nil {
dir = "."
}
}
dir += GetOSPathSlash() + ".gocryptotrader"
dir = filepath.Join(dir, ".gocryptotrader")
actualOutput := GetDefaultDataDir(runtime.GOOS)
if actualOutput != dir {
t.Fatalf("Unexpected result. Got: %v Expected: %v", actualOutput, dir)
Expand All @@ -982,12 +990,18 @@ func TestGetDefaultDataDir(t *testing.T) {
func TestCreateDir(t *testing.T) {
switch runtime.GOOS {
case "windows":
// test for looking up an invalid directory
err := CreateDir("")
if err == nil {
t.Fatal("expected err due to invalid path, but got nil")
}

// test for a directory that exists
dir, ok := os.LookupEnv("TEMP")
if !ok {
t.Fatal("LookupEnv failed. TEMP is not set")
}
err := CreateDir(dir)
err = CreateDir(dir)
if err != nil {
t.Fatalf("CreateDir failed. Err: %v", err)
}
Expand All @@ -1006,44 +1020,14 @@ func TestCreateDir(t *testing.T) {
if err != nil {
t.Fatalf("Failed to remove file. Err: %v", err)
}

// test for looking up an invalid directory
err = CreateDir("")
if err == nil {
t.Fatal("expected err due to invalid path, but got nil")
}
case "linux":
// same tests for linux
dir := "/home"
err := CreateDir(dir)
if err != nil {
t.Fatalf("CreateDir failed. Err: %v", err)
}
var ok bool
dir, ok = os.LookupEnv("HOME")
if !ok {
t.Fatal("LookupEnv of HOME failed")
}
dir = path.Join(dir, ".gocryptotrader", "TestFileASFG")
err = CreateDir(dir)
if err != nil {
t.Errorf("CreateDir failed. Err: %s", err)
}
err = os.Remove(dir)
if err != nil {
t.Fatalf("Failed to remove file. Err: %v", err)
}

// test for creating an invalid directory
err = CreateDir("")
default:
err := CreateDir("")
if err == nil {
t.Fatal("expected err due to invalid path, but got nil")
}

case "darwin":
// same test except for the invalid directory
dir := "/home"
err := CreateDir(dir)
err = CreateDir(dir)
if err != nil {
t.Fatalf("CreateDir failed. Err: %v", err)
}
Expand All @@ -1052,60 +1036,43 @@ func TestCreateDir(t *testing.T) {
if !ok {
t.Fatal("LookupEnv of HOME failed")
}
dir = path.Join(dir, ".gocryptotrader", "TestFileASFG")
dir = filepath.Join(dir, ".gocryptotrader", "TestFileASFG")
err = CreateDir(dir)
if err != nil {
t.Fatalf("CreateDir failed. Err: %s", err)
t.Errorf("CreateDir failed. Err: %s", err)
}
err = os.Remove(dir)
if err != nil {
t.Fatalf("Failed to remove file. Err: %v", err)
}

err = CreateDir(":")
if err == nil {
t.Fatal("expected err due to invalid path, but got nil")
}
}
}

func TestChangePerm(t *testing.T) {
switch runtime.GOOS {
case "linux", "darwin":
if runtime.GOOS == "linux" {
err := ChangePerm("")
if err == nil {
t.Fatal("expected an error on non-existent path")
}
} else {
err := ChangePerm(":")
if err == nil {
t.Fatal("expected an error on non-existent path")
}
case "windows":
err := ChangePerm("*")
if err == nil {
t.Fatal("expected an error on non-existent path")
}
err := os.Mkdir(GetDefaultDataDir(runtime.GOOS)+GetOSPathSlash()+"TestFileASDFGHJ", 0777)
err = os.Mkdir(GetDefaultDataDir(runtime.GOOS)+GetOSPathSlash()+"TestFileASDFGHJ", 0777)
if err != nil {
t.Fatalf("Mkdir failed. Err: %v", err)
}
err = ChangePerm(GetDefaultDataDir(runtime.GOOS))
if err != nil {
t.Fatal("ChangePerm was unsuccessful")
t.Fatalf("ChangePerm was unsuccessful. Err: %v", err)
}
var a os.FileInfo
a, err = os.Stat(GetDefaultDataDir(runtime.GOOS) + GetOSPathSlash() + "TestFileASDFGHJ")
_, err = os.Stat(GetDefaultDataDir(runtime.GOOS) + GetOSPathSlash() + "TestFileASDFGHJ")
if err != nil {
t.Fatalf("os.Stat failed. Err: %v", err)
}
if a.Mode().Perm() != 0770 {
t.Fatalf("expected file permissions differ. expecting 0770 got %#o", a.Mode().Perm())
}
err = RemoveFile(GetDefaultDataDir(runtime.GOOS) + GetOSPathSlash() + "TestFileASDFGHJ")
if err != nil {
t.Fatalf("RemoveFile failed. Err: %v", err)
}

case "windows":
err := ChangePerm("*")
default:
err := ChangePerm("")
if err == nil {
t.Fatal("expected an error on non-existent path")
}
Expand All @@ -1117,10 +1084,14 @@ func TestChangePerm(t *testing.T) {
if err != nil {
t.Fatalf("ChangePerm was unsuccessful. Err: %v", err)
}
_, err = os.Stat(GetDefaultDataDir(runtime.GOOS) + GetOSPathSlash() + "TestFileASDFGHJ")
var a os.FileInfo
a, err = os.Stat(GetDefaultDataDir(runtime.GOOS) + GetOSPathSlash() + "TestFileASDFGHJ")
if err != nil {
t.Fatalf("os.Stat failed. Err: %v", err)
}
if a.Mode().Perm() != 0770 {
t.Fatalf("expected file permissions differ. expecting 0770 got %#o", a.Mode().Perm())
}
err = RemoveFile(GetDefaultDataDir(runtime.GOOS) + GetOSPathSlash() + "TestFileASDFGHJ")
if err != nil {
t.Fatalf("RemoveFile failed. Err: %v", err)
Expand Down
17 changes: 10 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -124,10 +124,13 @@ type Config struct {
SMS *SMSGlobalConfig `json:"smsGlobal,omitempty"`
}

// ProfilerConfig defines the profiler configuration to enable pprof
type ProfilerConfig struct {
Enabled bool `json:"enabled"`
}

// NTPClientConfig defines a network time protocol configuration to allow for
// positive and negative differences
type NTPClientConfig struct {
Level int `json:"enabled"`
Pool []string `json:"pool"`
Expand Down Expand Up @@ -1089,7 +1092,7 @@ func (c *Config) CheckLoggerConfig() error {
}

if len(c.Logging.File) > 0 {
logPath := path.Join(common.GetDefaultDataDir(runtime.GOOS), "logs")
logPath := filepath.Join(common.GetDefaultDataDir(runtime.GOOS), "logs")
err := common.CreateDir(logPath)
if err != nil {
return err
Expand All @@ -1099,7 +1102,7 @@ func (c *Config) CheckLoggerConfig() error {
return nil
}

// CheckNTPConfig() checks for missing or incorrectly configured NTPClient and recreates with known safe defaults
// CheckNTPConfig checks for missing or incorrectly configured NTPClient and recreates with known safe defaults
func (c *Config) CheckNTPConfig() {
m.Lock()
defer m.Unlock()
Expand All @@ -1120,7 +1123,7 @@ func (c *Config) CheckNTPConfig() {
}
}

// DisableNTPCheck() allows the user to change how they are prompted for timesync alerts
// DisableNTPCheck allows the user to change how they are prompted for timesync alerts
func (c *Config) DisableNTPCheck(input io.Reader) (string, error) {
m.Lock()
defer m.Unlock()
Expand Down Expand Up @@ -1187,7 +1190,7 @@ func GetFilePath(file string) (string, error) {
if os.IsNotExist(err) {
continue
} else {
if path.Ext(oldDirs[x]) == ".json" {
if filepath.Ext(oldDirs[x]) == ".json" {
err = os.Rename(oldDirs[x], newDirs[0])
if err != nil {
return "", err
Expand Down Expand Up @@ -1216,7 +1219,7 @@ func GetFilePath(file string) (string, error) {
}

if ConfirmECS(data) {
if path.Ext(newDirs[x]) == ".dat" {
if filepath.Ext(newDirs[x]) == ".dat" {
return newDirs[x], nil
}

Expand All @@ -1227,7 +1230,7 @@ func GetFilePath(file string) (string, error) {
return newDirs[1], nil
}

if path.Ext(newDirs[x]) == ".json" {
if filepath.Ext(newDirs[x]) == ".json" {
return newDirs[x], nil
}

Expand Down
6 changes: 3 additions & 3 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"runtime"
"time"
)
Expand Down Expand Up @@ -87,13 +87,13 @@ func clearAllLoggers() {
// TODO: Fix up rotating at the moment its a quick job
func setupOutputs() (err error) {
if len(Logger.File) > 0 {
logFile := path.Join(LogPath, Logger.File)
logFile := filepath.Join(LogPath, Logger.File)
if Logger.Rotate {
if _, err = os.Stat(logFile); !os.IsNotExist(err) {
currentTime := time.Now()
newName := currentTime.Format("2006-01-02 15-04-05")
newFile := newName + " " + Logger.File
err = os.Rename(logFile, path.Join(LogPath, newFile))
err = os.Rename(logFile, filepath.Join(LogPath, newFile))
if err != nil {
err = fmt.Errorf("failed to rename old log file %s", err)
return
Expand Down
Loading

0 comments on commit 2f1405e

Please sign in to comment.