diff --git a/udp/server_libcoap_test.go b/udp/server_libcoap_test.go index d9318ad6..738f36d7 100644 --- a/udp/server_libcoap_test.go +++ b/udp/server_libcoap_test.go @@ -4,12 +4,6 @@ import ( "bytes" "errors" "fmt" - "math/rand" - "os/exec" - "strconv" - "sync" - "testing" - "github.com/plgd-dev/go-coap/v3/message" "github.com/plgd-dev/go-coap/v3/message/codes" "github.com/plgd-dev/go-coap/v3/mux" @@ -17,6 +11,11 @@ import ( "github.com/plgd-dev/go-coap/v3/options" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "math/rand" + "os/exec" + "strconv" + "sync" + "testing" ) func TestConnGetBlockwise(t *testing.T) { @@ -76,7 +75,7 @@ func TestConnGetBlockwise(t *testing.T) { err = m.Handle("/big", mux.HandlerFunc(func(w mux.ResponseWriter, r *mux.Message) { assert.Equal(t, codes.GET, r.Code()) - errS := w.SetResponse(codes.Content, message.AppOctets, bytes.NewReader([]byte(bigPayload10KiB))) + errS := w.SetResponse(codes.Content, message.AppOctets, bytes.NewReader(bigPayload10KiB)) require.NoError(t, errS) require.NotEmpty(t, w.Conn()) require.Equal(t, message.Confirmable, r.Type()) @@ -92,7 +91,6 @@ func TestConnGetBlockwise(t *testing.T) { errS := s.Serve(l) assert.NoError(t, errS) }() - cc, err := Dial(l.LocalAddr().String()) require.NoError(t, err) defer func() { @@ -233,7 +231,7 @@ func TestConnPostBlockwise(t *testing.T) { wantCode: codes.Content, wantErr: false, useToken: true, - wantPayload: []byte(bigPayload10KiB), + wantPayload: bigPayload10KiB, }, { name: "block-post-without-token", @@ -243,7 +241,7 @@ func TestConnPostBlockwise(t *testing.T) { wantCode: codes.Content, wantErr: false, useToken: false, - wantPayload: []byte(bigPayload10KiB), + wantPayload: bigPayload10KiB, }, } @@ -267,7 +265,7 @@ func TestConnPostBlockwise(t *testing.T) { err = m.Handle("/big", mux.HandlerFunc(func(w mux.ResponseWriter, r *mux.Message) { assert.Equal(t, codes.POST, r.Code()) received, err2 := r.ReadBody() - errS := w.SetResponse(codes.Content, message.TextPlain, bytes.NewReader([]byte(bigPayload10KiB))) + errS := w.SetResponse(codes.Content, message.TextPlain, bytes.NewReader(bigPayload10KiB)) require.NoError(t, err2) assert.Equal(t, bigPayload10KiB, received) require.NoError(t, errS) @@ -322,8 +320,7 @@ func sendCoAPRequestLibCoAP(address string, method string, path string, payload var args []string args = append(args, "-m", method) if token { - rand.Uint64() - args = append(args, "-T", strconv.FormatUint(rand.Uint64(), 10)) + args = append(args, "-T", strconv.FormatUint(uint64(rand.Uint32()), 16)) } if payload { args = append(args, "-b", "1024") @@ -347,7 +344,7 @@ func sendCoAPRequestLibCoAP(address string, method string, path string, payload return out.Bytes(), nil } -const bigPayload10KiB = `89075337635954647102216077828334038179638965680796041208684221958292459041499210220101176726750119361506928946801115768179724 +var bigPayload10KiB = []byte(`89075337635954647102216077828334038179638965680796041208684221958292459041499210220101176726750119361506928946801115768179724 42244632672758898527798766326186965189573496725417576843236332384515325066967967084729236662659424427203830789178855960389888 59671607161000645588293584669984665020199777828148967747970527020608102921980556435899241646582421992569038754973449362160805 31239955776017464552148435666505635723861800404618684226812752076597749931057757306056294943547000781262839809899923354086591 @@ -428,4 +425,4 @@ const bigPayload10KiB = `8907533763595464710221607782833403817963896568079604120 91655282321189488943674583928812971734718557687261267540861951330156857260194972959320584575281425950364513866555614168110966 87585502488315874658362449099439868192063303681917995993161431685969345689815394695246096186072665320424126902383281639806078 13897268972795607841085430069511881664533488909312510299548807790607510574162189448464719710343594178873230685172521870698370 -6337814198009624212201025856162445` +6337814198009624212201025856162445`)