Skip to content

Commit

Permalink
Merge pull request #368 from wakatime/feature/integration-tests
Browse files Browse the repository at this point in the history
Add integration tests
  • Loading branch information
dron22 authored May 15, 2021
2 parents f99629f + eda25f4 commit 15e43ba
Show file tree
Hide file tree
Showing 11 changed files with 538 additions and 141 deletions.
163 changes: 142 additions & 21 deletions .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,179 @@
name: "Unit Tests"
name: "Tests"

on:
push:
branches-ignore:
- "develop"
- "master"
on: push

env:
GO_VERSION: "1.16"
TEST_VERSION: "v0.0.1-test"

jobs:
test:
name: Test
name: Unit tests
runs-on: ubuntu-latest
steps:
-
-
name: "Checkout"
uses: actions/checkout@v2
-
-
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
-
-
name: "Pull dependencies"
run: go mod vendor
-
-
name: "Unit tests"
run: make test
-
-
name: "Linter"
run: make lint
-
name: "Send coverage"
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out


test-integration:
name: Integration tests
runs-on: ubuntu-latest
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
-
name: "Pull dependencies"
run: go mod vendor
-
name: "Build binary"
env:
VERSION: ${{ env.TEST_VERSION }}
run: make build-linux-amd64
-
name: "Integration tests"
run: make test-integration


test-windows:
name: Test Windows
name: Unit tests windows
runs-on: windows-latest
steps:
-
-
name: "Checkout"
uses: actions/checkout@v2
-
-
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
-
-
name: "Pull dependencies"
run: go mod vendor
-
-
name: "Unit tests"
run: make test
-
name: "Linter"
run: make lint

test-integration-windows:
name: Integration tests windows
runs-on: windows-latest
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
-
name: "Pull dependencies"
run: go mod vendor
-
name: "Build binary"
env:
VERSION: ${{ env.TEST_VERSION }}
run: make build-windows-amd64
-
name: "Integration tests"
run: make test-integration

test-macos:
name: Unit tests macos
runs-on: macos-latest
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
-
name: "Pull dependencies"
run: go mod vendor
-
name: "Unit tests"
run: make test

test-integration-macos:
name: Integration tests macos
runs-on: macos-latest
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
-
name: "Pull dependencies"
run: go mod vendor
-
name: "Build binary"
env:
VERSION: ${{ env.TEST_VERSION }}
run: make build-darwin-amd64
-
name: "Integration tests"
run: make test-integration

release:
name: Release
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' }}
runs-on: ubuntu-latest
needs: [test, test-integration, test-windows, test-integration-windows, test-macos, test-integration-macos]
steps:
-
name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: "Calculate semver tag"
id: semver-tag
uses: wakatime/[email protected]
with:
prerelease_id: "alpha"
-
name: Changelog
uses: gandarez/[email protected]
id: changelog
with:
current_tag: ${{ github.sha }}
previous_tag: ${{ steps.semver-tag.outputs.ancestor_tag }}
exclude: |
^Merge pull request .*
-
name: "Create release"
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.semver-tag.outputs.semver_tag }}
tag_name: ${{ steps.semver-tag.outputs.semver_tag }}
body: ${{ steps.changelog.outputs.changelog }}
prerelease: ${{ steps.semver-tag.outputs.is_prerelease }}
env:
# PAT is mandatory here to trigger new workflows
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
96 changes: 0 additions & 96 deletions .github/workflows/on_push_protected_branches.yml

This file was deleted.

9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# globals
BINARY_NAME?=wakatime-cli
BUILD_DIR?="./build"
COMMIT?=$(shell git rev-parse --short HEAD)
DATE?=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
REPO=github.com/wakatime/wakatime-cli
Expand Down Expand Up @@ -103,12 +104,12 @@ build-windows-amd64:
build-binary:
CGO_ENABLED="0" GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -v \
-ldflags "${LD_FLAGS} -X ${REPO}/pkg/version.OS=$(GOOS) -X ${REPO}/pkg/version.Arch=$(GOARCH)" \
-o ./build/$(BINARY_NAME)-$(GOOS)-$(GOARCH)
-o ${BUILD_DIR}/$(BINARY_NAME)-$(GOOS)-$(GOARCH)

build-binary-windows:
CGO_ENABLED="0" GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -v \
-ldflags "${LD_FLAGS} -X ${REPO}/pkg/version.OS=$(GOOS) -X ${REPO}/pkg/version.Arch=$(GOARCH)" \
-o ./build/$(BINARY_NAME)-$(GOOS)-$(GOARCH).exe
-o ${BUILD_DIR}/$(BINARY_NAME)-$(GOOS)-$(GOARCH).exe

# install linter
.PHONY: install-linter
Expand All @@ -126,3 +127,7 @@ lint: install-linter
.PHONY: test
test:
go test -race -covermode=atomic -coverprofile=coverage.out ./...

.PHONY: test-integration
test-integration:
go test -race -tags=integration ./main_test.go
44 changes: 22 additions & 22 deletions cmd/legacy/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ import (

// Run executes legacy commands following the interface of the old python implementation of the WakaTime script.
func Run(v *viper.Viper) {
if v.GetBool("useragent") {
log.Debugln("command: useragent")

if plugin := v.GetString("plugin"); plugin != "" {
fmt.Println(heartbeat.UserAgent(plugin))

os.Exit(exitcode.Success)
}

fmt.Println(heartbeat.UserAgentUnknownPlugin())

os.Exit(exitcode.Success)
}

if v.GetBool("version") {
log.Debugln("command: version")

runVersion(v.GetBool("verbose"))

os.Exit(exitcode.Success)
}

if err := config.ReadInConfig(v, config.FilePath); err != nil {
log.Errorf("failed to load configuration file: %s", err)

Expand Down Expand Up @@ -50,28 +72,6 @@ func Run(v *viper.Viper) {

log.SetVerbose(logfileParams.Verbose)

if v.GetBool("useragent") {
log.Debugln("command: useragent")

if plugin := v.GetString("plugin"); plugin != "" {
fmt.Println(heartbeat.UserAgent(plugin))

os.Exit(exitcode.Success)
}

fmt.Println(heartbeat.UserAgentUnknownPlugin())

os.Exit(exitcode.Success)
}

if v.GetBool("version") {
log.Debugln("command: version")

runVersion(v.GetBool("verbose"))

os.Exit(exitcode.Success)
}

if v.IsSet("config-read") {
log.Debugln("command: config-read")

Expand Down
Loading

0 comments on commit 15e43ba

Please sign in to comment.