diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..69fa345 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,35 @@ +name: Test + +# Replaces the Prow jobs pull-appkit-go-test and post-appkit-go-test. +on: + pull_request: + paths: + - '**.go' + - 'go.mod' + - 'go.sum' + - '.github/workflows/test.yaml' + push: + branches: + - master + paths: + - '**.go' + - 'go.mod' + - 'go.sum' + - '.github/workflows/test.yaml' + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version-file: go.mod + + - run: go test ./... diff --git a/log/log_test.go b/log/log_test.go index b72ebe4..3a72c84 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -4,8 +4,9 @@ import ( "context" "errors" "fmt" - "go/build" "io" + "path/filepath" + "runtime" "strings" "testing" "time" @@ -77,8 +78,15 @@ func TestLogError(t *testing.T) { } } +// moduleRoot is the directory of the appkit module. The stack traces +// have absolute file paths, and the expected values do not. +var moduleRoot = func() string { + _, file, _, _ := runtime.Caller(0) + return filepath.Dir(filepath.Dir(file)) +}() + func cleanStacktrace(stacktrace string) (cleantrace string) { - cleantrace = strings.Replace(stacktrace, build.Default.GOPATH+"/src/", "", -1) + cleantrace = strings.Replace(stacktrace, moduleRoot+"/", "github.com/theplant/appkit/", -1) lines := strings.Split(cleantrace, "\n") if len(lines) >= 4 { lines = lines[0:5]