Skip to content

Commit

Permalink
Merge pull request #92 from davidovich/modernize
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
davidovich committed Jan 1, 2024
2 parents 97532ce + 9836aef commit 00baa93
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 636 deletions.
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
SHELL=/bin/bash

export GO111MODULE := on
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

SCAFFOLD_BIN := bin/scaffold
SRCS = $(shell go list -buildvcs=false -f '{{ $$dir := .Dir}}{{range .GoFiles}}{{ printf "%s/%s\n" $$dir . }}{{end}}' $(1)/... github.com/davidovich/summon/...)

DOC_REPO_NAME := davidovich.github.io
DOC_REPO := [email protected]:davidovich/$(DOC_REPO_NAME).git
SUMMON_BADGE_JSON_FILE := $(DOC_REPO_NAME)/shields/summon/summon.json
TEST_TIMEOUT := 30s

GOTESTSUM_VERSION=latest
gotestsum := build/gotestsum

TEST_COMMAND := $(gotestsum) --format pkgname --packages="./..." -- -timeout $(TEST_TIMEOUT)

ASSETS := $(shell find internal/scaffold/templates/scaffold)

Expand All @@ -32,7 +38,10 @@ COVERAGE_PERCENT_FILE := build/coverage/percent.txt
HTML_COVERAGE := build/coverage/index.html

.PHONY: test
test: clean-coverage output-coverage
test: $(gotestsum) clean-coverage output-coverage

$(gotestsum):
GOBIN=$(ROOT_DIR)/build go install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)

.PHONY: clean-coverage
clean-coverage:
Expand All @@ -51,7 +60,7 @@ $(HTML_COVERAGE): $(COVERAGE)

$(COVERAGE):
@mkdir -p $(@D)
go test -buildvcs=false ./... -timeout 30s --coverpkg=./... -coverprofile $@ -v
$(TEST_COMMAND) -buildvcs=false --coverpkg=./... -coverprofile $@ -v

.PHONY: update-coverage-badge
update-coverage-badge: $(COVERAGE_PERCENT_FILE)
Expand Down
11 changes: 4 additions & 7 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,16 @@ func Test_RootCmdWithRunnables(t *testing.T) {
t.Run(strconv.Itoa(i)+"_"+tt.name, func(t *testing.T) {
s, rootCmd := makeRootCmd(true, tt.args...)

stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
execCommand := testutil.FakeExecCommand("TestSummonRunHelper", stdout, stderr)
execCommand := testutil.FakeExecCommand("TestSummonRunHelper")

s.Configure(summon.ExecCmd(execCommand))
s.Configure(summon.ExecCmd(execCommand.Fn))

if err := rootCmd.Execute(); (err != nil) != tt.wantErr {
t.Errorf("Execute() error = %v, wantErr %v", err, tt.wantErr)
}

c, err := testutil.GetCalls(stderr)
assert.Nil(t, err)
assert.Equal(t, c.Calls[0].Args, tt.expectedCall)
c := execCommand.GetCalls()
assert.Equal(t, c[0].Args, tt.expectedCall)
})
}
}
Expand Down
16 changes: 6 additions & 10 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bytes"
"embed"
"testing"

Expand Down Expand Up @@ -68,11 +67,9 @@ func TestRunCmd(t *testing.T) {
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
s, _ := summon.New(cmdTestFS)
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
execCommand := testutil.FakeExecCommand("TestSummonRunHelper", stdout, stderr)
execCommand := testutil.FakeExecCommand("TestSummonRunHelper")

err := s.Configure(summon.ExecCmd(execCommand))
err := s.Configure(summon.ExecCmd(execCommand.Fn))
assert.NoError(t, err)

injectOsArgs := append([]string{"summon"}, tC.args...)
Expand All @@ -86,13 +83,12 @@ func TestRunCmd(t *testing.T) {
}
require.NoError(t, err)

c, err := testutil.GetCalls(stderr)
assert.Nil(t, err)
c := execCommand.GetCalls()
if tC.noCalls {
assert.Len(t, c.Calls, 0)
assert.Len(t, c, 0)
} else {
require.Greater(t, len(c.Calls), 0, "should have made call")
assert.Equal(t, tC.callArgs, c.Calls[0].Args)
require.Greater(t, len(c), 0, "should have made call")
assert.Equal(t, tC.callArgs, c[0].Args)
}
})
}
Expand Down
38 changes: 19 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
module github.com/davidovich/summon

go 1.18
go 1.21

require (
github.com/DiSiqueira/GoTree v1.0.1-0.20190529205929-3e23dcd4532b
github.com/Masterminds/sprig/v3 v3.2.2
github.com/google/go-cmp v0.5.8
github.com/Masterminds/sprig/v3 v3.2.3
github.com/google/go-cmp v0.6.0
github.com/lithammer/dedent v1.1.0
github.com/spf13/afero v1.8.2
github.com/spf13/cobra v1.4.0
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.1
golang.org/x/exp v0.0.0-20220428152302-39d4317da171
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect
golang.org/x/text v0.3.7 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.6.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
Loading

0 comments on commit 00baa93

Please sign in to comment.