github.com/latiif/helm@v2.15.0+incompatible/cmd/tiller/probes_test.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"net/http"
    21  	"net/http/httptest"
    22  	"testing"
    23  )
    24  
    25  func TestProbesServer(t *testing.T) {
    26  	mux := newProbesMux()
    27  	srv := httptest.NewServer(mux)
    28  	defer srv.Close()
    29  	resp, err := http.Get(srv.URL + "/readiness")
    30  	if err != nil {
    31  		t.Fatalf("GET /readiness returned an error (%s)", err)
    32  	}
    33  	if resp.StatusCode != http.StatusOK {
    34  		t.Fatalf("GET /readiness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
    35  	}
    36  
    37  	resp, err = http.Get(srv.URL + "/liveness")
    38  	if err != nil {
    39  		t.Fatalf("GET /liveness returned an error (%s)", err)
    40  	}
    41  	if resp.StatusCode != http.StatusOK {
    42  		t.Fatalf("GET /liveness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
    43  	}
    44  }
    45  
    46  func TestPrometheus(t *testing.T) {
    47  	mux := http.NewServeMux()
    48  	addPrometheusHandler(mux)
    49  	srv := httptest.NewServer(mux)
    50  	defer srv.Close()
    51  	resp, err := http.Get(srv.URL + "/metrics")
    52  	if err != nil {
    53  		t.Fatalf("GET /metrics returned an error (%s)", err)
    54  	}
    55  	if resp.StatusCode != http.StatusOK {
    56  		t.Fatalf("GET /metrics returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
    57  	}
    58  }