Minor improvements

This commit is contained in:
TwinProduction 2021-02-19 20:34:35 -05:00
parent 50435f4030
commit 9b893aa4e0
4 changed files with 9 additions and 8 deletions

View File

@ -64,8 +64,8 @@ func TestAlertProvider_ToCustomAlertProvider(t *testing.T) {
if customAlertProvider == nil { if customAlertProvider == nil {
t.Fatal("customAlertProvider shouldn't have been nil") t.Fatal("customAlertProvider shouldn't have been nil")
} }
if customAlertProvider != customAlertProvider { if customAlertProvider.URL != "http://example.com" {
t.Error("customAlertProvider should've been equal to customAlertProvider") t.Error("expected URL to be http://example.com, got", customAlertProvider.URL)
} }
} }

View File

@ -213,9 +213,10 @@ func (service *Service) call(result *Result) {
result.Errors = append(result.Errors, err.Error()) result.Errors = append(result.Errors, err.Error())
return return
} }
defer response.Body.Close()
if response.TLS != nil && len(response.TLS.PeerCertificates) > 0 { if response.TLS != nil && len(response.TLS.PeerCertificates) > 0 {
certificate := response.TLS.PeerCertificates[0] certificate := response.TLS.PeerCertificates[0]
result.CertificateExpiration = certificate.NotAfter.Sub(time.Now()) result.CertificateExpiration = time.Until(certificate.NotAfter)
} }
result.HTTPStatus = response.StatusCode result.HTTPStatus = response.StatusCode
result.Connected = response.StatusCode > 0 result.Connected = response.StatusCode > 0

View File

@ -16,13 +16,13 @@ import (
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
) )
// KubernetesClientApi is a minimal interface for interacting with Kubernetes // KubernetesClientAPI is a minimal interface for interacting with Kubernetes
// Created mostly to make mocking the Kubernetes client easier // Created mostly to make mocking the Kubernetes client easier
type KubernetesClientApi interface { type KubernetesClientAPI interface {
GetServices(namespace string) ([]v1.Service, error) GetServices(namespace string) ([]v1.Service, error)
} }
// KubernetesClient is a working implementation of KubernetesClientApi // KubernetesClient is a working implementation of KubernetesClientAPI
type KubernetesClient struct { type KubernetesClient struct {
client *kubernetes.Clientset client *kubernetes.Clientset
} }
@ -44,7 +44,7 @@ func NewKubernetesClient(client *kubernetes.Clientset) *KubernetesClient {
} }
// NewClient creates a Kubernetes client for the given ClusterMode // NewClient creates a Kubernetes client for the given ClusterMode
func NewClient(clusterMode ClusterMode) (KubernetesClientApi, error) { func NewClient(clusterMode ClusterMode) (KubernetesClientAPI, error) {
var kubeConfig *rest.Config var kubeConfig *rest.Config
var err error var err error
switch clusterMode { switch clusterMode {

View File

@ -5,6 +5,6 @@ import (
) )
// GetKubernetesServices return a list of Services from the given namespace // GetKubernetesServices return a list of Services from the given namespace
func GetKubernetesServices(client KubernetesClientApi, namespace string) ([]v1.Service, error) { func GetKubernetesServices(client KubernetesClientAPI, namespace string) ([]v1.Service, error) {
return client.GetServices(namespace) return client.GetServices(namespace)
} }