github.com/bazelbuild/rules_webtesting@v0.2.0/go/wtl/proxy/proxy_test.go (about)

     1  // Copyright 2017 Google Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package proxy
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"net/http"
    21  	"os"
    22  	"testing"
    23  
    24  	"github.com/bazelbuild/rules_webtesting/go/httphelper"
    25  )
    26  
    27  func TestHTTPSProxy(t *testing.T) {
    28  	address, ok := os.LookupEnv("WEB_TEST_HTTPS_SERVER")
    29  	if !ok {
    30  		t.Fatal("expected environment variable WEB_TEST_HTTPS_SERVER to be defined")
    31  	}
    32  
    33  	ctx := context.Background()
    34  
    35  	url := fmt.Sprintf("%s/healthz", address)
    36  	resp, err := httphelper.Get(ctx, url)
    37  	if err != nil {
    38  		t.Fatal(err)
    39  	}
    40  	resp.Body.Close()
    41  	if resp.StatusCode != http.StatusOK {
    42  		t.Fatalf("Got status code %d expected %d", resp.StatusCode, http.StatusOK)
    43  	}
    44  }
    45  
    46  func TestHTTPProxy(t *testing.T) {
    47  	address, ok := os.LookupEnv("WEB_TEST_HTTP_SERVER")
    48  	if !ok {
    49  		t.Fatal("expected environment variable WEB_TEST_HTTP_SERVER to be defined")
    50  	}
    51  
    52  	ctx := context.Background()
    53  
    54  	url := fmt.Sprintf("%s/healthz", address)
    55  	resp, err := httphelper.Get(ctx, url)
    56  	if err != nil {
    57  		t.Fatal(err)
    58  	}
    59  	resp.Body.Close()
    60  	if resp.StatusCode != http.StatusOK {
    61  		t.Fatalf("Got status code %d expected %d", resp.StatusCode, http.StatusOK)
    62  	}
    63  }