github.com/avenga/couper@v1.12.2/utils/path_test.go (about)

     1  package utils_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/avenga/couper/utils"
     7  )
     8  
     9  func TestUtils_JoinPath(t *testing.T) {
    10  	if p := utils.JoinPath(); p != "" {
    11  		t.Errorf("Unexpected path %q given, expected %q", p, "")
    12  	}
    13  	if p := utils.JoinPath("/", "", ""); p != "/" {
    14  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    15  	}
    16  	if p := utils.JoinPath("", "/", ""); p != "/" {
    17  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    18  	}
    19  	if p := utils.JoinPath("", "", "/"); p != "/" {
    20  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    21  	}
    22  	if p := utils.JoinPath("/", "/", "/"); p != "/" {
    23  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    24  	}
    25  	if p := utils.JoinPath("/", "/foo", "/"); p != "/foo/" {
    26  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/")
    27  	}
    28  	if p := utils.JoinPath("/", "/", "//"); p != "/" {
    29  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    30  	}
    31  	if p := utils.JoinPath("/foo", "/bar"); p != "/foo/bar" {
    32  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/bar")
    33  	}
    34  	if p := utils.JoinPath("/foo", "/bar/"); p != "/foo/bar/" {
    35  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/bar/")
    36  	}
    37  	if p := utils.JoinPath("/foo/", "/bar/"); p != "/foo/bar/" {
    38  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/bar/")
    39  	}
    40  	if p := utils.JoinPath("/foo", "/./."); p != "/foo" {
    41  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo")
    42  	}
    43  	if p := utils.JoinPath("/foo", "/.."); p != "/" {
    44  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    45  	}
    46  }
    47  
    48  func TestUtils_JoinOpenAPIPath(t *testing.T) {
    49  	if p := utils.JoinOpenAPIPath(); p != "" {
    50  		t.Errorf("Unexpected path %q given, expected %q", p, "")
    51  	}
    52  	if p := utils.JoinOpenAPIPath("/", "", ""); p != "/" {
    53  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    54  	}
    55  	if p := utils.JoinOpenAPIPath("", "/", ""); p != "/" {
    56  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    57  	}
    58  	if p := utils.JoinOpenAPIPath("", "", "/"); p != "/" {
    59  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    60  	}
    61  	if p := utils.JoinOpenAPIPath("/", "/", "/"); p != "/" {
    62  		t.Errorf("Unexpected path %q given, expected %q", p, "/")
    63  	}
    64  	if p := utils.JoinOpenAPIPath("/", "/foo", "/"); p != "/foo" {
    65  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo")
    66  	}
    67  	if p := utils.JoinOpenAPIPath("/", "/", "//"); p != "//" {
    68  		t.Errorf("Unexpected path %q given, expected %q", p, "//")
    69  	}
    70  	if p := utils.JoinOpenAPIPath("/foo", "/bar"); p != "/foo/bar" {
    71  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/bar")
    72  	}
    73  	if p := utils.JoinOpenAPIPath("/foo", "/bar/"); p != "/foo/bar/" {
    74  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/bar/")
    75  	}
    76  	if p := utils.JoinOpenAPIPath("/foo/", "/bar//"); p != "/foo/bar//" {
    77  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/bar//")
    78  	}
    79  	if p := utils.JoinOpenAPIPath("/foo", "/./."); p != "/foo/./." {
    80  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/./.")
    81  	}
    82  	if p := utils.JoinOpenAPIPath("/foo/", "/../"); p != "/foo/../" {
    83  		t.Errorf("Unexpected path %q given, expected %q", p, "/foo/../")
    84  	}
    85  }