Skip to content

Commit

Permalink
remove dep on assert lib
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Feb 2, 2019
1 parent 2a0f359 commit bdd71a4
Show file tree
Hide file tree
Showing 35 changed files with 365 additions and 324 deletions.
17 changes: 9 additions & 8 deletions app/stats/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (

"v2ray.com/core/app/stats"
. "v2ray.com/core/app/stats/command"
"v2ray.com/core/common"
. "v2ray.com/ext/assert"
)

func TestGetStats(t *testing.T) {
assert := With(t)

m, err := stats.NewManager(context.Background(), &stats.Config{})
assert(err, IsNil)
common.Must(err)

sc, err := m.RegisterCounter("test_counter")
assert(err, IsNil)
common.Must(err)

sc.Set(1)

Expand Down Expand Up @@ -50,7 +51,7 @@ func TestGetStats(t *testing.T) {
if tc.err {
assert(err, IsNotNil)
} else {
assert(err, IsNil)
common.Must(err)
assert(resp.Stat.Name, Equals, tc.name)
assert(resp.Stat.Value, Equals, tc.value)
}
Expand All @@ -61,25 +62,25 @@ func TestQueryStats(t *testing.T) {
assert := With(t)

m, err := stats.NewManager(context.Background(), &stats.Config{})
assert(err, IsNil)
common.Must(err)

sc1, err := m.RegisterCounter("test_counter")
assert(err, IsNil)
common.Must(err)
sc1.Set(1)

sc2, err := m.RegisterCounter("test_counter_2")
assert(err, IsNil)
common.Must(err)
sc2.Set(2)

sc3, err := m.RegisterCounter("test_counter_3")
assert(err, IsNil)
common.Must(err)
sc3.Set(3)

s := NewStatsServer(m)
resp, err := s.QueryStats(context.Background(), &QueryStatsRequest{
Pattern: "counter_",
})
assert(err, IsNil)
common.Must(err)
assert(len(resp.Stat), Equals, 2)

v2 := false
Expand Down
6 changes: 3 additions & 3 deletions common/buf/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func TestBytesReaderWriteTo(t *testing.T) {
writer.SetBuffered(false)

nBytes, err := io.Copy(writer, reader)
assert(err, IsNil)
common.Must(err)
assert(nBytes, Equals, int64(6))

mb, err := pReader2.ReadMultiBuffer()
assert(err, IsNil)
common.Must(err)
assert(len(mb), Equals, 2)
assert(mb[0].String(), Equals, "abc")
assert(mb[1].String(), Equals, "efg")
Expand All @@ -52,7 +52,7 @@ func TestBytesReaderMultiBuffer(t *testing.T) {

mbReader := NewReader(reader)
mb, err := mbReader.ReadMultiBuffer()
assert(err, IsNil)
common.Must(err)
assert(len(mb), Equals, 2)
assert(mb[0].String(), Equals, "abc")
assert(mb[1].String(), Equals, "efg")
Expand Down
8 changes: 4 additions & 4 deletions common/buf/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestWriter(t *testing.T) {
writer := NewBufferedWriter(NewWriter(writeBuffer))
writer.SetBuffered(false)
err := writer.WriteMultiBuffer(MultiBuffer{lb})
assert(err, IsNil)
common.Must(err)
assert(writer.Flush(), IsNil)
assert(expectedBytes, Equals, writeBuffer.Bytes())
}
Expand All @@ -46,7 +46,7 @@ func TestBytesWriterReadFrom(t *testing.T) {
}

mb, err := pReader.ReadMultiBuffer()
assert(err, IsNil)
common.Must(err)
assert(mb.Len(), Equals, int32(size))
}

Expand All @@ -58,7 +58,7 @@ func TestDiscardBytes(t *testing.T) {

nBytes, err := io.Copy(DiscardBytes, b)
assert(nBytes, Equals, int64(Size))
assert(err, IsNil)
common.Must(err)
}

func TestDiscardBytesMultiBuffer(t *testing.T) {
Expand All @@ -71,7 +71,7 @@ func TestDiscardBytesMultiBuffer(t *testing.T) {
r := NewReader(buffer)
nBytes, err := io.Copy(DiscardBytes, &BufferedReader{Reader: r})
assert(nBytes, Equals, int64(size))
assert(err, IsNil)
common.Must(err)
}

func TestWriterInterface(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions common/crypto/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestAuthenticationReaderWriter(t *testing.T) {
key := make([]byte, 16)
rand.Read(key)
block, err := aes.NewCipher(key)
assert(err, IsNil)
common.Must(err)

aead, err := cipher.NewGCM(block)
assert(err, IsNil)
common.Must(err)

const payloadSize = 1024 * 80
rawPayload := make([]byte, payloadSize)
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestAuthenticationReaderWriter(t *testing.T) {

for mb.Len() < payloadSize {
mb2, err := reader.ReadMultiBuffer()
assert(err, IsNil)
common.Must(err)

mb, _ = buf.MergeMulti(mb, mb2)
}
Expand All @@ -78,10 +78,10 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
key := make([]byte, 16)
common.Must2(rand.Read(key))
block, err := aes.NewCipher(key)
assert(err, IsNil)
common.Must(err)

aead, err := cipher.NewGCM(block)
assert(err, IsNil)
common.Must(err)

cache := buf.New()
iv := make([]byte, 12)
Expand All @@ -105,7 +105,7 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
assert(writer.WriteMultiBuffer(payload), IsNil)
assert(cache.Len(), GreaterThan, int32(0))
assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil)
assert(err, IsNil)
common.Must(err)

reader := NewAuthenticationReader(&AEADAuthenticator{
AEAD: aead,
Expand All @@ -114,7 +114,7 @@ func TestAuthenticationReaderWriterPacket(t *testing.T) {
}, PlainChunkSizeParser{}, cache, protocol.TransferTypePacket, nil)

mb, err := reader.ReadMultiBuffer()
assert(err, IsNil)
common.Must(err)

mb, b1 := buf.SplitFirst(mb)
assert(b1.String(), Equals, "abcd")
Expand Down
2 changes: 1 addition & 1 deletion common/crypto/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestChunkStreamIO(t *testing.T) {
assert(mb[0].Bytes(), Equals, []byte("abcd"))

mb, err = reader.ReadMultiBuffer()
assert(err, IsNil)
common.Must(err)
assert(mb.Len(), Equals, int32(3))
assert(mb[0].Bytes(), Equals, []byte("efg"))

Expand Down
25 changes: 13 additions & 12 deletions common/mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"testing"

"v2ray.com/core/common"
"v2ray.com/core/common/buf"
. "v2ray.com/core/common/mux"
"v2ray.com/core/common/net"
Expand Down Expand Up @@ -63,72 +64,72 @@ func TestReaderWriter(t *testing.T) {

var meta FrameMetadata
err := meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(meta.SessionID, Equals, uint16(1))
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
assert(meta.Target, Equals, dest)
assert(byte(meta.Option), Equals, byte(OptionData))

data, err := readAll(NewStreamReader(bytesReader))
assert(err, IsNil)
common.Must(err)
assert(len(data), Equals, 1)
assert(data[0].String(), Equals, "abcd")

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
assert(meta.SessionID, Equals, uint16(2))
assert(byte(meta.Option), Equals, byte(0))
assert(meta.Target, Equals, dest2)

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
assert(meta.SessionID, Equals, uint16(1))
assert(byte(meta.Option), Equals, byte(1))

data, err = readAll(NewStreamReader(bytesReader))
assert(err, IsNil)
common.Must(err)
assert(len(data), Equals, 1)
assert(data[0].String(), Equals, "efgh")

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusNew))
assert(meta.SessionID, Equals, uint16(3))
assert(byte(meta.Option), Equals, byte(1))
assert(meta.Target, Equals, dest3)

data, err = readAll(NewStreamReader(bytesReader))
assert(err, IsNil)
common.Must(err)
assert(len(data), Equals, 1)
assert(data[0].String(), Equals, "x")

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
assert(meta.SessionID, Equals, uint16(1))
assert(byte(meta.Option), Equals, byte(0))

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
assert(meta.SessionID, Equals, uint16(3))
assert(byte(meta.Option), Equals, byte(0))

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusKeep))
assert(meta.SessionID, Equals, uint16(2))
assert(byte(meta.Option), Equals, byte(1))

data, err = readAll(NewStreamReader(bytesReader))
assert(err, IsNil)
common.Must(err)
assert(len(data), Equals, 1)
assert(data[0].String(), Equals, "y")

err = meta.Unmarshal(bytesReader)
assert(err, IsNil)
common.Must(err)
assert(byte(meta.SessionStatus), Equals, byte(SessionStatusEnd))
assert(meta.SessionID, Equals, uint16(2))
assert(byte(meta.Option), Equals, byte(0))
Expand Down
5 changes: 3 additions & 2 deletions common/platform/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"runtime"
"testing"

"v2ray.com/core/common"
. "v2ray.com/core/common/platform"
. "v2ray.com/ext/assert"
)
Expand Down Expand Up @@ -47,7 +48,7 @@ func TestGetAssetLocation(t *testing.T) {
assert := With(t)

exec, err := os.Executable()
assert(err, IsNil)
common.Must(err)

loc := GetAssetLocation("t")
assert(filepath.Dir(loc), Equals, filepath.Dir(exec))
Expand All @@ -64,7 +65,7 @@ func TestGetPluginLocation(t *testing.T) {
assert := With(t)

exec, err := os.Executable()
assert(err, IsNil)
common.Must(err)

loc := GetPluginDirectory()
assert(loc, Equals, filepath.Join(filepath.Dir(exec), "plugins"))
Expand Down
4 changes: 2 additions & 2 deletions common/protocol/http/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"testing"

"v2ray.com/core/common"
"v2ray.com/core/common/net"

. "v2ray.com/core/common/protocol/http"
. "v2ray.com/ext/assert"
)
Expand Down Expand Up @@ -41,7 +41,7 @@ Accept-Language: de,en;q=0.7,en-us;q=0.3
`
b := bufio.NewReader(strings.NewReader(rawRequest))
req, err := http.ReadRequest(b)
assert(err, IsNil)
common.Must(err)
assert(req.Header.Get("Foo"), Equals, "foo")
assert(req.Header.Get("Bar"), Equals, "bar")
assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")
Expand Down
7 changes: 4 additions & 3 deletions common/retry/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"v2ray.com/core/common"
"v2ray.com/core/common/errors"
. "v2ray.com/core/common/retry"
. "v2ray.com/ext/assert"
Expand All @@ -22,7 +23,7 @@ func TestNoRetry(t *testing.T) {
})
endTime := time.Now().Unix()

assert(err, IsNil)
common.Must(err)
assert(endTime-startTime, AtLeast, int64(0))
}

Expand All @@ -40,7 +41,7 @@ func TestRetryOnce(t *testing.T) {
})
duration := time.Since(startTime)

assert(err, IsNil)
common.Must(err)
assert(int64(duration/time.Millisecond), AtLeast, int64(900))
}

Expand All @@ -58,7 +59,7 @@ func TestRetryMultiple(t *testing.T) {
})
duration := time.Since(startTime)

assert(err, IsNil)
common.Must(err)
assert(int64(duration/time.Millisecond), AtLeast, int64(4900))
}

Expand Down
Loading

0 comments on commit bdd71a4

Please sign in to comment.