Skip to content

Commit 6243bb6

Browse files
committed
task test refactor
1 parent 8aa0eb2 commit 6243bb6

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

.github/workflows/test-go-task.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ jobs:
9999
- name: Run tests
100100
env:
101101
GO_MODULE_PATH: ${{ matrix.module.path }}
102-
# run: task go:test ## TODO: refactor the tests
103-
run: task go:test:docker
102+
run: task go:test
104103

105104
- name: Send unit tests coverage to Codecov
106105
if: runner.os == 'Linux'

Taskfile.yaml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
version: "3"
32

43
vars:
@@ -11,9 +10,6 @@ vars:
1110
go list ./... | tr '\n' ' ' ||
1211
echo '"ERROR: Unable to discover Go packages"'
1312
)
14-
# `-ldflags` flag to use for `go build` command
15-
# TODO: define flag if required by the project, or leave empty if not needed.
16-
LDFLAGS:
1713
1814
tasks:
1915
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-go-task/Taskfile.yml
@@ -47,19 +43,6 @@ tasks:
4743
go:test:
4844
desc: Run unit tests
4945
dir: "{{default .DEFAULT_GO_MODULE_PATH .GO_MODULE_PATH}}"
50-
cmds:
51-
- |
52-
go test \
53-
-v \
54-
-short \
55-
-run '{{default ".*" .GO_TEST_REGEX}}' \
56-
{{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} \
57-
-coverprofile=coverage_unit.txt \
58-
{{.TEST_LDFLAGS}} \
59-
{{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}
60-
61-
go:test:docker:
62-
desc: Run the tests inside a docker image
6346
cmds:
6447
- docker build -f testdata/Dockerfile -t go-apt-test:latest .
65-
- docker run --rm go-apt-test
48+
- docker run --rm -v "$PWD":/app go-apt-test -v -short -run '{{default ".*" .GO_TEST_REGEX}}' {{default "-timeout 10m -coverpkg=./... -covermode=atomic" .GO_TEST_FLAGS}} -coverprofile=coverage_unit.txt {{default .DEFAULT_GO_PACKAGES .GO_PACKAGES}}

apt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestCheckForUpdates(t *testing.T) {
7171
}
7272

7373
func TestParseListUpgradableOutput(t *testing.T) {
74-
t.Run("special cases", func(t *testing.T) {
74+
t.Run("edges cases", func(t *testing.T) {
7575
tests := []struct {
7676
name string
7777
input string
@@ -84,7 +84,7 @@ func TestParseListUpgradableOutput(t *testing.T) {
8484
},
8585
{
8686
name: "line not matching regex",
87-
input: "this-is-not-a-valid-line\n",
87+
input: "this-is-not a-valid-line\n",
8888
expected: []*Package{},
8989
},
9090
{

testdata/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ RUN apt-get update && apt-get install -y \
1010
WORKDIR /app
1111

1212
# Copy everything (mod files + code)
13-
COPY . .
13+
COPY go.mod go.sum ./
1414

1515
# Download modules
1616
RUN go mod download
1717

1818
# Run tests in apt package
19-
CMD ["go", "test", "-v", "./"]
19+
ENTRYPOINT ["go", "test"]

0 commit comments

Comments
 (0)