Add OS X CI Matrix support to Travis (#284)

Add OS X CI Matrix support to Travis
This commit is contained in:
Ryan O'Hara-Reid
2019-04-30 15:27:16 +10:00
committed by Adrian Gallagher
parent 88bc17a17f
commit 2f1405ead4
6 changed files with 99 additions and 102 deletions

View File

@@ -1,6 +1,7 @@
matrix:
include:
- language: node_js
name: 'GoCryptoTrader [front-end]'
node_js:
- '10'
- '8'
@@ -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:

View File

@@ -20,7 +20,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"os/user"
"path/filepath"
"reflect"
"regexp"
@@ -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")
}
return path.Join(dir, ".gocryptotrader")
dir, err := os.UserHomeDir()
if err != nil {
log.Warn("Environment variable unset, defaulting to current directory")
dir = "."
}
return filepath.Join(dir, ".gocryptotrader")
}
// CreateDir creates a directory based on the supplied parameter

View File

@@ -4,7 +4,8 @@ import (
"bytes"
"net/url"
"os"
"path"
"os/user"
"path/filepath"
"reflect"
"runtime"
"strings"
@@ -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)
@@ -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)
}
@@ -1006,16 +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("")
default:
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)
err = CreateDir(dir)
if err != nil {
t.Fatalf("CreateDir failed. Err: %v", err)
}
@@ -1024,7 +1036,7 @@ 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.Errorf("CreateDir failed. Err: %s", err)
@@ -1033,77 +1045,11 @@ func TestCreateDir(t *testing.T) {
if err != nil {
t.Fatalf("Failed to remove file. Err: %v", err)
}
// test for creating an invalid directory
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)
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.Fatalf("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")
}
}
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")
}
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)
}
case "windows":
err := ChangePerm("*")
if err == nil {
@@ -1125,5 +1071,30 @@ func TestChangePerm(t *testing.T) {
if err != nil {
t.Fatalf("RemoveFile failed. Err: %v", err)
}
default:
err := ChangePerm("")
if err == nil {
t.Fatal("expected an error on non-existent path")
}
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.Fatalf("ChangePerm was unsuccessful. Err: %v", err)
}
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)
}
}
}

View File

@@ -8,7 +8,7 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
@@ -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"`
@@ -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
@@ -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()
@@ -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()
@@ -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
@@ -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
}
@@ -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
}

View File

@@ -6,7 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"path"
"path/filepath"
"runtime"
"time"
)
@@ -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

View File

@@ -2,7 +2,7 @@ package logger
import (
"os"
"path"
"path/filepath"
"testing"
)
@@ -24,7 +24,7 @@ func TestCloseLogFile(t *testing.T) {
if err != nil {
t.Fatalf("CloseLogFile failed with %v", err)
}
os.Remove(path.Join(LogPath, Logger.File))
os.Remove(filepath.Join(LogPath, Logger.File))
}
func TestSetupOutputsValidPath(t *testing.T) {
@@ -41,7 +41,7 @@ func TestSetupOutputsValidPath(t *testing.T) {
t.Fatalf("CloseLogFile failed with %v", err)
}
err = os.Remove(path.Join(LogPath, Logger.File))
err = os.Remove(filepath.Join(LogPath, Logger.File))
if err != nil {
t.Fatal("Test Failed - SetupOutputsValidPath() error could not remove test file", err)
}
@@ -57,7 +57,7 @@ func TestSetupOutputsInValidPath(t *testing.T) {
t.Fatalf("SetupOutputs failed expected %v got %v", os.ErrNotExist, err)
}
}
err = os.Remove(path.Join(LogPath, Logger.File))
err = os.Remove(filepath.Join(LogPath, Logger.File))
if err == nil {
t.Fatal("Test Failed - SetupOutputsInValidPath() error cannot be nil")
}