Skip to content

Commit

Permalink
Add mockery to try it (#13)
Browse files Browse the repository at this point in the history
* fix: refactor code and add some tests; bump some dependencies

* Fix typo

* Fix typo
  • Loading branch information
isindir authored Mar 12, 2022
1 parent 8b3a0c0 commit a66afde
Show file tree
Hide file tree
Showing 11 changed files with 707 additions and 170 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
if: github.ref != 'refs/heads/master'
steps:

- name: Set up Go 1.17.8
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.17.8
Expand All @@ -23,6 +23,7 @@ jobs:
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: v1.6.3
install-only: true

- name: Check out code into the Go module directory
Expand All @@ -43,7 +44,7 @@ jobs:
if: github.ref == 'refs/heads/master'
steps:

- name: Set up Go 1.17.8
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.17.8
Expand All @@ -52,6 +53,7 @@ jobs:
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: v1.6.3
install-only: true

- name: Install svu
Expand Down
4 changes: 3 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
# https://golang.org/dl/
golang 1.17.8
# https://github.com/goreleaser/goreleaser/releases
goreleaser 1.6.0
goreleaser 1.6.3
# https://github.com/vektra/mockery/releases
mockery 2.10.0
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ run: ## Runs main help
test: ## Placeholder to run unit tests
@echo "Running unit tests"
@mkdir -p bin
$(GO) test -cover -coverprofile=bin/c.out ./...
$(GO) test -cover -coverprofile=bin/c.out $$( go list ./... | egrep -v 'mocks|qqq|vendor|exec|cmd' )
$(GO) tool cover -html=bin/c.out -o bin/coverage.html
@echo

Expand All @@ -52,8 +52,14 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
$(GO) vet ./...

.PHONY: mockery
mockery: ## Regenerate mock files
for i in exec gitlab; do \
(cd $$i; rm -fr mocks; mockery --all) ;\
done

.PHONY: mod
mod: ## Run go mod tidy/vendor
mod: mockery ## Run go mod tidy/vendor
$(GO) mod tidy
$(GO) mod vendor

Expand Down
38 changes: 38 additions & 0 deletions exec/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package exec

import (
"bytes"
"os/exec"
)

const gitCmd = "git"

type ShellRunnerI interface {
ExecGitCommand(args []string, stdoutb *bytes.Buffer, erroutb *bytes.Buffer, dir string) (cmd *exec.Cmd, err error)
}

type ShellRunner struct{}

// ExecGitCommand executes git with flags passed as `args` and can change working directory if `dir` is passed
func (repo *ShellRunner) ExecGitCommand(
args []string,
stdoutb *bytes.Buffer,
erroutb *bytes.Buffer,
dir string,
) (cmd *exec.Cmd, err error) {
cmd = exec.Command(gitCmd, args...)

if stdoutb != nil {
cmd.Stdout = stdoutb
}
if erroutb != nil {
cmd.Stderr = erroutb
}

if dir != "" {
cmd.Dir = dir
}

err = cmd.Run()
return cmd, err
}
38 changes: 38 additions & 0 deletions exec/mocks/ShellRunnerI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a66afde

Please sign in to comment.