...

Source file src/k8s.io/kube-aggregator/pkg/controllers/status/metrics_test.go

Documentation: k8s.io/kube-aggregator/pkg/controllers/status

     1  /*
     2  Copyright 2020 The Kubernetes 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 apiserver
    18  
    19  import (
    20  	"strings"
    21  	"testing"
    22  
    23  	"k8s.io/component-base/metrics/testutil"
    24  )
    25  
    26  func TestAPIServiceAvailabilityCollection(t *testing.T) {
    27  	collector := newAvailabilityCollector()
    28  
    29  	availableAPIService := "available"
    30  	unavailableAPIService := "unavailable"
    31  
    32  	collector.SetAPIServiceAvailable(availableAPIService)
    33  	collector.SetAPIServiceUnavailable(unavailableAPIService)
    34  
    35  	err := testutil.CustomCollectAndCompare(collector, strings.NewReader(`
    36  	# HELP aggregator_unavailable_apiservice [ALPHA] Gauge of APIServices which are marked as unavailable broken down by APIService name.
    37  	# TYPE aggregator_unavailable_apiservice gauge
    38  	aggregator_unavailable_apiservice{name="available"} 0
    39  	aggregator_unavailable_apiservice{name="unavailable"} 1
    40  	`))
    41  	if err != nil {
    42  		t.Fatal(err)
    43  	}
    44  
    45  	collector.ClearState()
    46  
    47  	collector.ForgetAPIService(availableAPIService)
    48  	collector.ForgetAPIService(unavailableAPIService)
    49  
    50  	err = testutil.CustomCollectAndCompare(collector, strings.NewReader(`
    51  	# HELP aggregator_unavailable_apiservice [ALPHA] Gauge of APIServices which are marked as unavailable broken down by APIService name.
    52  	# TYPE aggregator_unavailable_apiservice gauge
    53  	`))
    54  	if err != nil {
    55  		t.Fatal(err)
    56  	}
    57  }
    58  

View as plain text