Skip to content

Commit

Permalink
feat: add build
Browse files Browse the repository at this point in the history
  • Loading branch information
Azhovan committed Aug 25, 2024
1 parent a2d6211 commit 8c863ae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/go.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Build
run: go build -v ./...
go-version: '1.23'

- name: Test
run: go test -v ./...
run: go test -v ./... -race
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
APP_NAME := dr

VERSION :=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
REVISION :=$(shell git rev-parse HEAD)$(shell if git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)

OS ?=$(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH ?=$(shell go env GOARCH | tr '[:upper:]' '[:lower:]')

build:
@if [ -z "$(ARCH)" ]; then echo "mandatory ARCH field is empty"; exit 1; fi
@if [ -z "$(OS)" ]; then echo "mandatory OS field is empty"; exit 1; fi
@echo "Building for OS=$(OS), ARCH=$(ARCH), VERSION=$(VERSION), REVISION=$(REVISION)"
@GOOS=$(OS) GOARCH=$(ARCH) go build \
-ldflags "-X main.Version=$(VERSION) -X main.Revision=$(REVISION) -s -w" \
-trimpath -a -o $(APP_NAME)

test:
go test ./... -v

4 changes: 2 additions & 2 deletions pkg/download/dl_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestNewDownloadManager(t *testing.T) {
downloader, err := NewDownloader("/tmp/xxy/", "https://httpbin.org/range/512", WithLogger(log))
if assert.NoError(t, err) {
defer t.Cleanup(func() {
// os.RemoveAll("/tmp/xx/")
_ = os.RemoveAll("/tmp/xxy/")
})

dlManager := NewDownloadManager(downloader, DefaultRetryPolicy())
Expand All @@ -43,7 +43,7 @@ func TestNewDownloadManager(t *testing.T) {
downloader, err := NewDownloader("/tmp/xx/", server.URL)
if assert.NoError(t, err) {
defer t.Cleanup(func() {
os.RemoveAll("/tmp/xx/")
_ = os.RemoveAll("/tmp/xx/")
})

dlManager := NewDownloadManager(downloader, DefaultRetryPolicy())
Expand Down
2 changes: 1 addition & 1 deletion pkg/download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestNewDownloader(t *testing.T) {
filesize: 12,
gotTotalSegments: 2,
gotSegmentSize: 2,
wantErr: &InvalidParamError{param: "TotalSegments, SegmentSize", message: "these two properties are mutually exclusive"},
wantErr: &InvalidParamError{param: "TotalSegments, SegmentSize", message: "these two properties are mutually exclusive, set only one of them"},
},
}

Expand Down

0 comments on commit 8c863ae

Please sign in to comment.