Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:

lint:
test:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -47,6 +47,9 @@ jobs:
git diff --exit-code go.mod
git diff --exit-code go.sum

- name: Go Test
run: go test ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
Expand Down
4 changes: 3 additions & 1 deletion assert/must_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ func TestRespTest(t *testing.T) {
}

func TestRespNext(t *testing.T) {
Must(init1Next())
assert.Panics(t, func() {
Must(init1Next())
})
}

func init1Next() (err error) {
Expand Down
4 changes: 2 additions & 2 deletions async/promise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestPromise(t *testing.T) {
reject(err)
})

assert.Equal(t, future.Await().Err(), err)
assert.ErrorIs(t, future.Await().Err(), err)
})
}

Expand All @@ -49,7 +49,7 @@ func TestYield(t *testing.T) {
yield(3)
return err
})
assert.Equal(t, iter.Await().Err(), err)
assert.ErrorIs(t, iter.Await().Err(), err)
})
}

Expand Down
4 changes: 3 additions & 1 deletion errors/z_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ func TestWrapCaller(t *testing.T) {
return errors.WrapCaller(err, 1)
}

assert.Contains(t, fmt.Sprint(ff()), "z_code_test.go:20 TestWrapCaller")
errText := fmt.Sprint(ff())
assert.Contains(t, errText, "z_code_test.go:")
assert.Contains(t, errText, "TestWrapCaller")
}

func TestCodeErr(t *testing.T) {
Expand Down
32 changes: 28 additions & 4 deletions recovery/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package recovery_test

import (
"fmt"
"os"
"os/exec"
"testing"

"github.com/pubgo/funk/assert"
Expand All @@ -22,7 +24,18 @@ func testExit() {
}

func TestExit(t *testing.T) {
testExit1()
if os.Getenv("TEST_RECOVERY_EXIT") == "1" {
testExit1()
return
}

cmd := exec.Command(os.Args[0], "-test.run=^TestExit$")
cmd.Env = append(os.Environ(), "TEST_RECOVERY_EXIT=1")
err := cmd.Run()
if exitErr, ok := err.(*exec.ExitError); ok && !exitErr.Success() {
return
}
t.Fatalf("expected recovery.Exit to terminate with a non-zero status, got %v", err)
}

func TestErr(t *testing.T) {
Expand Down Expand Up @@ -67,8 +80,19 @@ func hello() {
}

func TestTesting(t *testing.T) {
defer recovery.Testing(t)
if os.Getenv("TEST_RECOVERY_TESTING") == "1" {
defer recovery.Testing(t)

log.Print("test panic")
hello()
log.Print("test panic")
hello()
return
}

cmd := exec.Command(os.Args[0], "-test.run=^TestTesting$")
cmd.Env = append(os.Environ(), "TEST_RECOVERY_TESTING=1")
err := cmd.Run()
if exitErr, ok := err.(*exec.ExitError); ok && !exitErr.Success() {
return
}
t.Fatalf("expected recovery.Testing to fail the subprocess test, got %v", err)
}
5 changes: 4 additions & 1 deletion v2/result/resultchecker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func errCheck1(ctx context.Context, err error) error {
_ = ctx
return err
}

Expand All @@ -19,7 +20,9 @@ func TestErrCheck(t *testing.T) {

assert.Equal(t, RegisterErrCheck(errCheck1), false)
assert.Equal(t, len(GetErrCheckStacks()), 1)
assert.Equal(t, GetErrCheckStacks()[0].Short(), "aherrcheck/errcheck_test.go:10 errCheck1")
short := GetErrCheckStacks()[0].Short()
assert.Contains(t, short, "resultchecker/checker_test.go:")
assert.Contains(t, short, "errCheck1")

RemoveErrCheck(errCheck1)
assert.Equal(t, len(GetErrCheckStacks()), 0)
Expand Down
24 changes: 20 additions & 4 deletions version/export.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
package version

import "os"

const (
envProject = "FUNK_PROJECT"
envVersion = "FUNK_VERSION"
envCommitID = "FUNK_COMMIT_ID"
envBuildTime = "FUNK_BUILD_TIME"
)

func CommitID() string {
return commitID
return lookupEnv(envCommitID, commitID)
}

func MainPath() string {
return mainPath
}

func Version() string {
return version
return lookupEnv(envVersion, version)
}

func BuildTime() string {
return buildTime
return lookupEnv(envBuildTime, buildTime)
}

func Project() string {
return project
return lookupEnv(envProject, project)
}

func lookupEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
Comment thread
chenzhongjie2 marked this conversation as resolved.
return fallback
}
47 changes: 47 additions & 0 deletions version/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package version

import "testing"

func TestVersionUsesEnvOverride(t *testing.T) {
t.Setenv(envVersion, "v9.9.9-test")
version = "v0.0.1"
Comment thread
chenzhongjie2 marked this conversation as resolved.

if got := Version(); got != "v9.9.9-test" {
t.Fatalf("Version() = %q, want %q", got, "v9.9.9-test")
}
}

func TestVersionFallsBackWithoutEnv(t *testing.T) {
version = "v1.2.3"
Comment thread
chenzhongjie2 marked this conversation as resolved.

if got := Version(); got != "v1.2.3" {
t.Fatalf("Version() = %q, want %q", got, "v1.2.3")
}
}

func TestCommitIDUsesEnvOverride(t *testing.T) {
t.Setenv(envCommitID, "commit-from-env")
commitID = "commit-from-build"
Comment thread
chenzhongjie2 marked this conversation as resolved.

if got := CommitID(); got != "commit-from-env" {
t.Fatalf("CommitID() = %q, want %q", got, "commit-from-env")
}
}

func TestBuildTimeUsesEnvOverride(t *testing.T) {
t.Setenv(envBuildTime, "2026-05-15T12:00:00Z")
buildTime = "2026-05-15T11:00:00Z"
Comment thread
chenzhongjie2 marked this conversation as resolved.

if got := BuildTime(); got != "2026-05-15T12:00:00Z" {
t.Fatalf("BuildTime() = %q, want %q", got, "2026-05-15T12:00:00Z")
}
}

func TestProjectUsesEnvOverride(t *testing.T) {
t.Setenv(envProject, "portal")
project = "project"
Comment thread
chenzhongjie2 marked this conversation as resolved.

if got := Project(); got != "portal" {
t.Fatalf("Project() = %q, want %q", got, "portal")
}
}
Loading