chore: add more tests (#2547)

master
Kevin Wan 2 years ago committed by GitHub
parent 06e4914e41
commit 46e236fef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)
})
}

@ -4,6 +4,7 @@
package stat package stat
import ( import (
"os"
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -12,6 +13,9 @@ import (
) )
func TestReport(t *testing.T) { func TestReport(t *testing.T) {
os.Setenv(clusterNameKey, "test-cluster")
defer os.Unsetenv(clusterNameKey)
var count int32 var count int32
SetReporter(func(s string) { SetReporter(func(s string) {
atomic.AddInt32(&count, 1) atomic.AddInt32(&count, 1)

@ -1,6 +1,7 @@
package internal package internal
import ( import (
"errors"
"fmt" "fmt"
"net/url" "net/url"
"strconv" "strconv"
@ -35,10 +36,17 @@ func TestDirectBuilder_Build(t *testing.T) {
target := fmt.Sprintf("%s:///%s", DirectScheme, strings.Join(servers, ",")) target := fmt.Sprintf("%s:///%s", DirectScheme, strings.Join(servers, ","))
uri, err := url.Parse(target) uri, err := url.Parse(target)
assert.Nil(t, err) assert.Nil(t, err)
cc.err = errors.New("foo")
_, err = b.Build(resolver.Target{ _, err = b.Build(resolver.Target{
URL: *uri, URL: *uri,
}, cc, resolver.BuildOptions{}) }, 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) size := mathx.MinInt(test, subsetSize)
assert.Equal(t, size, len(cc.state.Addresses)) assert.Equal(t, size, len(cc.state.Addresses))
m := make(map[string]lang.PlaceholderType) m := make(map[string]lang.PlaceholderType)

@ -16,11 +16,12 @@ func TestNopResolver(t *testing.T) {
type mockedClientConn struct { type mockedClientConn struct {
state resolver.State state resolver.State
err error
} }
func (m *mockedClientConn) UpdateState(state resolver.State) error { func (m *mockedClientConn) UpdateState(state resolver.State) error {
m.state = state m.state = state
return nil return m.err
} }
func (m *mockedClientConn) ReportError(err error) { func (m *mockedClientConn) ReportError(err error) {

Loading…
Cancel
Save