github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/cpio/utils_test.go (about)

     1  // Copyright 2013-2018 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package cpio
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestNormalize(t *testing.T) {
    12  	for _, tt := range []struct {
    13  		path string
    14  		want string
    15  	}{
    16  		{
    17  			path: "/foo/bar",
    18  			want: "foo/bar",
    19  		},
    20  		{
    21  			path: "foo////bar",
    22  			want: "foo/bar",
    23  		},
    24  		{
    25  			path: "/foo/bar/../baz",
    26  			want: "foo/baz",
    27  		},
    28  		{
    29  			path: "foo/bar/../baz",
    30  			want: "foo/baz",
    31  		},
    32  		{
    33  			path: "./foo/bar",
    34  			want: "foo/bar",
    35  		},
    36  		{
    37  			path: "foo/../../bar",
    38  			want: "../bar",
    39  		},
    40  		{
    41  			path: "",
    42  			want: ".",
    43  		},
    44  		{
    45  			path: ".",
    46  			want: ".",
    47  		},
    48  	} {
    49  		if got := Normalize(tt.path); got != tt.want {
    50  			t.Errorf("Normalize(%q) = %q, want %q", tt.path, got, tt.want)
    51  		}
    52  	}
    53  }