github.com/influx6/npkg@v0.8.8/npattrn/utils_test.go (about)

     1  package npattrn_test
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	pattern "github.com/influx6/npkg/npattrn"
     8  )
     9  
    10  func TestTrimEndSlashe(t *testing.T) {
    11  
    12  	cases := map[string]struct {
    13  		original, expected string
    14  	}{
    15  		"Single slash at the end of the string": struct {
    16  			original, expected string
    17  		}{
    18  			"/users/6/influx6/", "/users/6/influx6",
    19  		},
    20  		"Two slashes at the end of the string": struct {
    21  			original, expected string
    22  		}{
    23  			"/users/6/influx6//", "/users/6/influx6",
    24  		},
    25  	}
    26  
    27  	for k, v := range cases {
    28  		if got := pattern.TrimEndSlashe(v.original); !strings.EqualFold(got, v.expected) {
    29  			t.Fatalf(`Test for %s failed .\n. Expected %s.. Got %s`,
    30  				k, v.expected, got)
    31  		}
    32  	}
    33  }
    34  
    35  func TestTrimSlashes(t *testing.T) {
    36  
    37  	cases := map[string]struct {
    38  		original, expected string
    39  	}{
    40  		"Slash present only at the end of the string": struct {
    41  			original, expected string
    42  		}{
    43  			"users/6/influx6/", "users/6/influx6",
    44  		},
    45  		"Slashes present as a prefix and suffix": struct {
    46  			original, expected string
    47  		}{
    48  			"/users/6/influx6/", "users/6/influx6",
    49  		},
    50  	}
    51  
    52  	for k, v := range cases {
    53  
    54  		if got := pattern.TrimSlashes(v.original); !strings.EqualFold(got, v.expected) {
    55  			t.Fatalf(`
    56  				Test for %s failed \n..Expected %s. Got %s`,
    57  				k, v.expected, got)
    58  		}
    59  	}
    60  }