-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from go-exec/tests
Refactoring and tests
- Loading branch information
Showing
38 changed files
with
1,853 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
on: [push] | ||
name: tests | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.13] | ||
platform: [ubuntu-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
- name: Lint | ||
run: make lint | ||
- name: Tests | ||
run: make tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
examples/*/* | ||
!examples/*/*.go | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
all: | ||
|
||
lint-local: | ||
@echo "Running linters" | ||
golangci-lint cache clean | ||
golangci-lint run -v ./... | ||
|
||
lint: | ||
@echo "Running linters" | ||
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.21.0 golangci-lint run -v ./... | ||
|
||
tests: | ||
@echo "Running tests" | ||
@mkdir -p artifacts | ||
go test -race -count=1 -cover -coverprofile=artifacts/coverage.out -v ./... | ||
|
||
coverage: tests | ||
@echo "Running tests & coverage" | ||
go tool cover -html=artifacts/coverage.out -o artifacts/coverage.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package exec | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"reflect" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestConfig_Value(t *testing.T) { | ||
type testCase struct { | ||
test string | ||
cfg *config | ||
expectedPanic interface{} | ||
} | ||
|
||
testCases := []testCase{ | ||
{ | ||
test: "valid simple value", | ||
cfg: &config{ | ||
value: "", | ||
}, | ||
}, | ||
{ | ||
test: "valid func value", | ||
cfg: &config{ | ||
value: func() interface{} { | ||
return "value" | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: "panics on invalid func with input param", | ||
cfg: &config{ | ||
value: func(s string) interface{} { | ||
return "value" | ||
}, | ||
}, | ||
expectedPanic: "Function type must have no input parameters", | ||
}, | ||
{ | ||
test: "panics on invalid func with more than one return param", | ||
cfg: &config{ | ||
value: func() (interface{}, string) { | ||
return "value", "one" | ||
}, | ||
}, | ||
expectedPanic: "Function type must have a single return value", | ||
}, | ||
{ | ||
test: "panics on invalid func with no input param", | ||
cfg: &config{ | ||
value: func() string { | ||
return "value" | ||
}, | ||
}, | ||
expectedPanic: "Function return value must be an interface{}", | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.test, func(t *testing.T) { | ||
if testCase.expectedPanic != nil { | ||
require.PanicsWithValue(t, testCase.expectedPanic, func() { | ||
testCase.cfg.Value() | ||
}) | ||
} else { | ||
require.Equal(t, testCase.cfg.value, testCase.cfg.Value()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestConfig_String(t *testing.T) { | ||
cfg := &config{ | ||
Name: "name", | ||
value: "string", | ||
} | ||
|
||
require.Equal(t, cfg.value, cfg.String()) | ||
require.IsType(t, reflect.TypeOf(cfg.value), reflect.TypeOf(cfg.String())) | ||
} | ||
|
||
func TestConfig_Int(t *testing.T) { | ||
cfg := &config{ | ||
Name: "name", | ||
value: 1, | ||
} | ||
|
||
require.Equal(t, cfg.value, cfg.Int()) | ||
require.IsType(t, reflect.TypeOf(cfg.value), reflect.TypeOf(cfg.Int())) | ||
} | ||
|
||
func TestConfig_Int64(t *testing.T) { | ||
cfg := &config{ | ||
Name: "name", | ||
value: int64(1), | ||
} | ||
|
||
require.Equal(t, cfg.value, cfg.Int64()) | ||
require.IsType(t, reflect.TypeOf(cfg.value), reflect.TypeOf(cfg.Int64())) | ||
} | ||
|
||
func TestConfig_Bool(t *testing.T) { | ||
cfg := &config{ | ||
Name: "name", | ||
value: true, | ||
} | ||
|
||
require.Equal(t, cfg.value, cfg.Bool()) | ||
require.IsType(t, reflect.TypeOf(cfg.value), reflect.TypeOf(cfg.Bool())) | ||
} | ||
|
||
func TestConfig_Slice(t *testing.T) { | ||
cfg := &config{ | ||
Name: "name", | ||
value: []string{"a", "b"}, | ||
} | ||
|
||
require.Equal(t, cfg.value, cfg.Slice()) | ||
require.IsType(t, reflect.TypeOf(cfg.value), reflect.TypeOf(cfg.Slice())) | ||
} | ||
|
||
func TestConfig_Time(t *testing.T) { | ||
cfg := &config{ | ||
Name: "name", | ||
value: time.Now(), | ||
} | ||
|
||
require.Equal(t, cfg.value, cfg.Time()) | ||
require.IsType(t, reflect.TypeOf(cfg.value), reflect.TypeOf(cfg.Time())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ import ( | |
Example of deploying a Symfony app using the deploy recipes | ||
*/ | ||
func main() { | ||
exec := exec.Instance | ||
defer exec.Run() | ||
|
||
exec.Set("repository", "[email protected]:namespace/app.git") | ||
exec.Set("shared_files", []string{}) | ||
exec.Set("shared_dirs", []string{"var/logs", "vendor", "web/uploads", "web/media", "node_modules"}) | ||
|
@@ -38,6 +41,4 @@ func main() { | |
exec.OnServers(func() []string { | ||
return []string{exec.GetArgument("stage").String()} | ||
}) | ||
|
||
exec.Init() | ||
} |
Oops, something went wrong.