diff --git a/core/fs/files_test.go b/core/fs/files_test.go new file mode 100644 index 00000000..96ff174e --- /dev/null +++ b/core/fs/files_test.go @@ -0,0 +1,15 @@ +package fs + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCloseOnExec(t *testing.T) { + file := os.NewFile(0, os.DevNull) + assert.NotPanics(t, func() { + CloseOnExec(file) + }) +} diff --git a/core/stat/alert_test.go b/core/stat/alert_test.go index c5419698..0e95afb3 100644 --- a/core/stat/alert_test.go +++ b/core/stat/alert_test.go @@ -4,6 +4,7 @@ package stat import ( + "os" "strconv" "sync/atomic" "testing" @@ -12,6 +13,9 @@ import ( ) func TestReport(t *testing.T) { + os.Setenv(clusterNameKey, "test-cluster") + defer os.Unsetenv(clusterNameKey) + var count int32 SetReporter(func(s string) { atomic.AddInt32(&count, 1) diff --git a/zrpc/resolver/internal/directbuilder_test.go b/zrpc/resolver/internal/directbuilder_test.go index e311fcba..b602ccdd 100644 --- a/zrpc/resolver/internal/directbuilder_test.go +++ b/zrpc/resolver/internal/directbuilder_test.go @@ -1,6 +1,7 @@ package internal import ( + "errors" "fmt" "net/url" "strconv" @@ -35,10 +36,17 @@ func TestDirectBuilder_Build(t *testing.T) { target := fmt.Sprintf("%s:///%s", DirectScheme, strings.Join(servers, ",")) uri, err := url.Parse(target) assert.Nil(t, err) + cc.err = errors.New("foo") _, err = b.Build(resolver.Target{ URL: *uri, }, cc, resolver.BuildOptions{}) - assert.Nil(t, err) + assert.NotNil(t, err) + cc.err = nil + _, err = b.Build(resolver.Target{ + URL: *uri, + }, cc, resolver.BuildOptions{}) + assert.NoError(t, err) + size := mathx.MinInt(test, subsetSize) assert.Equal(t, size, len(cc.state.Addresses)) m := make(map[string]lang.PlaceholderType) diff --git a/zrpc/resolver/internal/resolver_test.go b/zrpc/resolver/internal/resolver_test.go index dde4065a..2f4a4690 100644 --- a/zrpc/resolver/internal/resolver_test.go +++ b/zrpc/resolver/internal/resolver_test.go @@ -16,11 +16,12 @@ func TestNopResolver(t *testing.T) { type mockedClientConn struct { state resolver.State + err error } func (m *mockedClientConn) UpdateState(state resolver.State) error { m.state = state - return nil + return m.err } func (m *mockedClientConn) ReportError(err error) {