service/dap: use constants for testing error codes (#2741)

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
polinasok 2021-10-10 06:57:06 -07:00 committed by GitHub
parent 3515be1db1
commit d613f8ec45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -269,15 +269,15 @@ func TestLaunchStopOnEntry(t *testing.T) {
// 9 >> stackTrace, << error // 9 >> stackTrace, << error
client.StackTraceRequest(1, 0, 20) client.StackTraceRequest(1, 0, 20)
stResp = client.ExpectInvisibleErrorResponse(t) stResp = client.ExpectInvisibleErrorResponse(t)
if stResp.Seq != 0 || stResp.RequestSeq != 9 || stResp.Body.Error.Id != 2004 { if stResp.Seq != 0 || stResp.RequestSeq != 9 || stResp.Body.Error.Id != UnableToProduceStackTrace {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=9 Id=2004", stResp) t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=9 Id=%d", stResp, UnableToProduceStackTrace)
} }
// 10 >> evaluate, << error // 10 >> evaluate, << error
client.EvaluateRequest("foo", 0 /*no frame specified*/, "repl") client.EvaluateRequest("foo", 0 /*no frame specified*/, "repl")
erResp := client.ExpectInvisibleErrorResponse(t) erResp := client.ExpectInvisibleErrorResponse(t)
if erResp.Seq != 0 || erResp.RequestSeq != 10 || erResp.Body.Error.Id != 2009 { if erResp.Seq != 0 || erResp.RequestSeq != 10 || erResp.Body.Error.Id != UnableToEvaluateExpression {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=10 Id=2009", erResp) t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=10 Id=%d", erResp, UnableToEvaluateExpression)
} }
// 11 >> evaluate, << evaluate // 11 >> evaluate, << evaluate
@ -411,8 +411,8 @@ func TestAttachStopOnEntry(t *testing.T) {
// 10 >> evaluate, << error // 10 >> evaluate, << error
client.EvaluateRequest("foo", 0 /*no frame specified*/, "repl") client.EvaluateRequest("foo", 0 /*no frame specified*/, "repl")
erResp := client.ExpectInvisibleErrorResponse(t) erResp := client.ExpectInvisibleErrorResponse(t)
if erResp.Seq != 0 || erResp.RequestSeq != 10 || erResp.Body.Error.Id != 2009 { if erResp.Seq != 0 || erResp.RequestSeq != 10 || erResp.Body.Error.Id != UnableToEvaluateExpression {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=10 Id=2009", erResp) t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=10 Id=%d", erResp, UnableToEvaluateExpression)
} }
// 11 >> evaluate, << evaluate // 11 >> evaluate, << evaluate
@ -5422,8 +5422,8 @@ func TestBadLaunchRequests(t *testing.T) {
if response.Message != "Failed to launch" { if response.Message != "Failed to launch" {
t.Errorf("Message got %q, want \"Failed to launch\"", response.Message) t.Errorf("Message got %q, want \"Failed to launch\"", response.Message)
} }
if response.Body.Error.Id != 3000 { if response.Body.Error.Id != FailedToLaunch {
t.Errorf("Id got %d, want 3000", response.Body.Error.Id) t.Errorf("Id got %d, want %d", response.Body.Error.Id, FailedToLaunch)
} }
seqCnt++ seqCnt++
} }
@ -5623,8 +5623,8 @@ func TestBadAttachRequest(t *testing.T) {
if response.Message != "Failed to attach" { if response.Message != "Failed to attach" {
t.Errorf("Message got %q, want \"Failed to attach\"", response.Message) t.Errorf("Message got %q, want \"Failed to attach\"", response.Message)
} }
if response.Body.Error.Id != 3001 { if response.Body.Error.Id != FailedToAttach {
t.Errorf("Id got %d, want 3001", response.Body.Error.Id) t.Errorf("Id got %d, want %d", response.Body.Error.Id, FailedToAttach)
} }
seqCnt++ seqCnt++
} }
@ -5688,8 +5688,8 @@ func TestBadAttachRequest(t *testing.T) {
if er.Body.Error.Format != "Internal Error: runtime error: index out of range [0] with length 0" { if er.Body.Error.Format != "Internal Error: runtime error: index out of range [0] with length 0" {
t.Errorf("Message got %q, want \"Internal Error: runtime error: index out of range [0] with length 0\"", er.Message) t.Errorf("Message got %q, want \"Internal Error: runtime error: index out of range [0] with length 0\"", er.Message)
} }
if er.Body.Error.Id != 8888 { if er.Body.Error.Id != InternalError {
t.Errorf("Id got %d, want 8888", er.Body.Error.Id) t.Errorf("Id got %d, want %d", er.Body.Error.Id, InternalError)
} }
// Bad "backend" // Bad "backend"
@ -5853,8 +5853,8 @@ func TestLaunchAttachErrorWhenDebugInProgress(t *testing.T) {
client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 100}) client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 100})
er := client.ExpectVisibleErrorResponse(t) er := client.ExpectVisibleErrorResponse(t)
msg := "Failed to attach: debugger already started - use remote mode to connect" msg := "Failed to attach: debugger already started - use remote mode to connect"
if er.Body.Error.Id != 3001 || er.Body.Error.Format != msg { if er.Body.Error.Id != FailedToAttach || er.Body.Error.Format != msg {
t.Errorf("got %#v, want Id=3001 Format=%q", er, msg) t.Errorf("got %#v, want Id=%d Format=%q", er, FailedToAttach, msg)
} }
tests := []string{"debug", "test", "exec", "replay", "core"} tests := []string{"debug", "test", "exec", "replay", "core"}
for _, mode := range tests { for _, mode := range tests {
@ -5862,8 +5862,8 @@ func TestLaunchAttachErrorWhenDebugInProgress(t *testing.T) {
client.LaunchRequestWithArgs(map[string]interface{}{"mode": mode}) client.LaunchRequestWithArgs(map[string]interface{}{"mode": mode})
er := client.ExpectVisibleErrorResponse(t) er := client.ExpectVisibleErrorResponse(t)
msg := "Failed to launch: debugger already started - use remote attach to connect to a server with an active debug session" msg := "Failed to launch: debugger already started - use remote attach to connect to a server with an active debug session"
if er.Body.Error.Id != 3000 || er.Body.Error.Format != msg { if er.Body.Error.Id != FailedToLaunch || er.Body.Error.Format != msg {
t.Errorf("got %#v, want Id=3001 Format=%q", er, msg) t.Errorf("got %#v, want Id=%d Format=%q", er, FailedToLaunch, msg)
} }
}) })
} }
@ -5887,8 +5887,8 @@ func TestBadInitializeRequest(t *testing.T) {
if response.Message != "Failed to initialize" { if response.Message != "Failed to initialize" {
t.Errorf("Message got %q, want \"Failed to launch\"", response.Message) t.Errorf("Message got %q, want \"Failed to launch\"", response.Message)
} }
if response.Body.Error.Id != 3002 { if response.Body.Error.Id != FailedToInitialize {
t.Errorf("Id got %d, want 3002", response.Body.Error.Id) t.Errorf("Id got %d, want %d", response.Body.Error.Id, FailedToInitialize)
} }
if response.Body.Error.Format != err { if response.Body.Error.Format != err {
t.Errorf("\ngot %q\nwant %q", response.Body.Error.Format, err) t.Errorf("\ngot %q\nwant %q", response.Body.Error.Format, err)