Skip to content

Commit

Permalink
refactor: testinit.go
Browse files Browse the repository at this point in the history
update workflow
  • Loading branch information
Tommi2Day committed Oct 27, 2023
1 parent d46e295 commit 94a7586
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: [push]
# SKIP_LDAP: true
# SKIP_MAIL: true
# SKIP_ORACLE: true

# SKIP_COMMIT: true
jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -16,9 +16,9 @@ jobs:
ports:
- 2375:2375
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
check-latest: true
Expand All @@ -27,9 +27,11 @@ jobs:
go mod tidy
go mod vendor
- name: Test
run: go test -v ./... -coverprofile=coverage.txt -covermode=atomic
env:
# github copies the files with api, not as clone, check fails
# https://github.com/actions/checkout/issues/335
SKIP_COMMIT: true
run: go test -v ./... -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
Expand Down
25 changes: 4 additions & 21 deletions test/testinit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package test defines path settings while testing
// Package test init test directories
package test

// https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009685279-Go-test-working-directory-keeps-changing-to-dir-of-the-test-file-instead-of-value-in-template
Expand All @@ -9,30 +9,13 @@ import (
"testing"
)

// TestDir working dir for tests
// TestDir working dir for test
var TestDir string

// TestData directory for working files
// TestData directory for working Attachments
var TestData string

func init() {
_, filename, _, _ := runtime.Caller(0)
dir := path.Dir(filename)
err := os.Chdir(dir)
if err != nil {
panic(err)
}
TestDir = dir
TestData = path.Join(TestDir, "testdata")
// create data directory and ignore errors
err = os.Mkdir(TestData, 0750)
if err != nil && !os.IsExist(err) {
panic(err)
}
println("Work in " + dir)
}

// Testinit alternative init Test directories
// Testinit set test directory
func Testinit(t *testing.T) {
_, filename, _, _ := runtime.Caller(0)
dir := path.Dir(filename)
Expand Down

0 comments on commit 94a7586

Please sign in to comment.