golang.org/x/tools/gopls@v0.15.3/internal/test/integration/misc/debugserver_test.go (about)

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package misc
     6  
     7  import (
     8  	"net/http"
     9  	"testing"
    10  
    11  	"golang.org/x/tools/gopls/internal/protocol"
    12  	"golang.org/x/tools/gopls/internal/protocol/command"
    13  
    14  	. "golang.org/x/tools/gopls/internal/test/integration"
    15  )
    16  
    17  func TestStartDebugging(t *testing.T) {
    18  	WithOptions(
    19  		Modes(Forwarded),
    20  	).Run(t, "", func(t *testing.T, env *Env) {
    21  		args, err := command.MarshalArgs(command.DebuggingArgs{})
    22  		if err != nil {
    23  			t.Fatal(err)
    24  		}
    25  		params := &protocol.ExecuteCommandParams{
    26  			Command:   command.StartDebugging.ID(),
    27  			Arguments: args,
    28  		}
    29  		var result command.DebuggingResult
    30  		env.ExecuteCommand(params, &result)
    31  		if got, want := len(result.URLs), 2; got != want {
    32  			t.Fatalf("got %d urls, want %d; urls: %#v", got, want, result.URLs)
    33  		}
    34  		for i, u := range result.URLs {
    35  			resp, err := http.Get(u)
    36  			if err != nil {
    37  				t.Errorf("getting url #%d (%q): %v", i, u, err)
    38  				continue
    39  			}
    40  			defer resp.Body.Close()
    41  			if got, want := resp.StatusCode, http.StatusOK; got != want {
    42  				t.Errorf("debug server #%d returned HTTP %d, want %d", i, got, want)
    43  			}
    44  		}
    45  	})
    46  }