github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/go/vcweb/vcweb_test.go (about)

     1  // Copyright 2022 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 vcweb_test
     6  
     7  import (
     8  	"io"
     9  	"log"
    10  	"net/http"
    11  	"net/http/httptest"
    12  	"os"
    13  	"testing"
    14  
    15  	"github.com/go-asm/go/cmd/go/vcweb"
    16  )
    17  
    18  func TestHelp(t *testing.T) {
    19  	s, err := vcweb.NewServer(os.DevNull, t.TempDir(), log.Default())
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	srv := httptest.NewServer(s)
    24  	defer srv.Close()
    25  
    26  	resp, err := http.Get(srv.URL + "/help")
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  	defer resp.Body.Close()
    31  
    32  	if resp.StatusCode != 200 {
    33  		t.Fatal(resp.Status)
    34  	}
    35  	body, err := io.ReadAll(resp.Body)
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	t.Logf("%s", body)
    40  }
    41  
    42  func TestOverview(t *testing.T) {
    43  	s, err := vcweb.NewServer(os.DevNull, t.TempDir(), log.Default())
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  	srv := httptest.NewServer(s)
    48  	defer srv.Close()
    49  
    50  	resp, err := http.Get(srv.URL)
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  	defer resp.Body.Close()
    55  
    56  	if resp.StatusCode != 200 {
    57  		t.Fatal(resp.Status)
    58  	}
    59  	body, err := io.ReadAll(resp.Body)
    60  	if err != nil {
    61  		t.Fatal(err)
    62  	}
    63  	t.Logf("%s", body)
    64  }