...

Source file src/github.com/linkerd/linkerd2/pkg/k8s/k8s_test.go

Documentation: github.com/linkerd/linkerd2/pkg/k8s

     1  package k8s
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestGetConfig(t *testing.T) {
     8  	t.Run("Gets host correctly form existing file", func(t *testing.T) {
     9  		config, err := GetConfig("testdata/config.test", "")
    10  		if err != nil {
    11  			t.Fatalf("Unexpected error: %v", err)
    12  		}
    13  
    14  		expectedHost := "https://55.197.171.239"
    15  		if config.Host != expectedHost {
    16  			t.Fatalf("Expected host to be [%s] got [%s]", expectedHost, config.Host)
    17  		}
    18  	})
    19  
    20  	t.Run("Returns error if configuration cannot be found", func(t *testing.T) {
    21  		_, err := GetConfig("/this/doest./not/exist.config", "")
    22  		if err == nil {
    23  			t.Fatalf("Expecting error when config file does not exist, got nothing")
    24  		}
    25  	})
    26  }
    27  
    28  func TestCanonicalResourceNameFromFriendlyName(t *testing.T) {
    29  	t.Run("Returns canonical name for all known variants", func(t *testing.T) {
    30  		expectations := map[string]string{
    31  			"po":           Pod,
    32  			"pod":          Pod,
    33  			"deployment":   Deployment,
    34  			"deployments":  Deployment,
    35  			"au":           Authority,
    36  			"authorities":  Authority,
    37  			"cj":           CronJob,
    38  			"cronjob":      CronJob,
    39  			"serverauthz":  ServerAuthorization,
    40  			"srvauthz":     ServerAuthorization,
    41  			"authzpolicy":  AuthorizationPolicy,
    42  			"meshtlsauthn": MeshTLSAuthentication,
    43  			"networkauthn": NetworkAuthentication,
    44  			"netauthn":     NetworkAuthentication,
    45  		}
    46  
    47  		for input, expectedName := range expectations {
    48  			actualName, err := CanonicalResourceNameFromFriendlyName(input)
    49  			if err != nil {
    50  				t.Fatalf("Unexpected error: %v", err)
    51  			}
    52  
    53  			if actualName != expectedName {
    54  				t.Fatalf("Expected friendly name [%s] to resolve to [%s], but got [%s]", input, expectedName, actualName)
    55  			}
    56  		}
    57  	})
    58  
    59  	t.Run("Returns error if input isn't a supported name", func(t *testing.T) {
    60  		unsupportedNames := []string{
    61  			"pdo", "dop", "paths", "path", "", "mesh",
    62  		}
    63  
    64  		for _, n := range unsupportedNames {
    65  			out, err := CanonicalResourceNameFromFriendlyName(n)
    66  			if err == nil {
    67  				t.Fatalf("Expecting error when resolving [%s], but it did resolve to [%s]", n, out)
    68  			}
    69  		}
    70  	})
    71  }
    72  

View as plain text