github.com/sdboyer/gps@v0.16.3/strip_vendor_nonwindows_test.go (about)

     1  // +build !windows
     2  
     3  package gps
     4  
     5  import "testing"
     6  
     7  func TestStripVendorSymlinks(t *testing.T) {
     8  	t.Run("vendor symlink", stripVendorTestCase(fsTestCase{
     9  		before: filesystemState{
    10  			dirs: []fsPath{
    11  				fsPath{"package"},
    12  				fsPath{"package", "_vendor"},
    13  			},
    14  			links: []fsLink{
    15  				fsLink{
    16  					path: fsPath{"package", "vendor"},
    17  					to:   "_vendor",
    18  				},
    19  			},
    20  		},
    21  		after: filesystemState{
    22  			dirs: []fsPath{
    23  				fsPath{"package"},
    24  				fsPath{"package", "_vendor"},
    25  			},
    26  		},
    27  	}))
    28  
    29  	t.Run("nonvendor symlink", stripVendorTestCase(fsTestCase{
    30  		before: filesystemState{
    31  			dirs: []fsPath{
    32  				fsPath{"package"},
    33  				fsPath{"package", "_vendor"},
    34  			},
    35  			links: []fsLink{
    36  				fsLink{
    37  					path: fsPath{"package", "link"},
    38  					to:   "_vendor",
    39  				},
    40  			},
    41  		},
    42  		after: filesystemState{
    43  			dirs: []fsPath{
    44  				fsPath{"package"},
    45  				fsPath{"package", "_vendor"},
    46  			},
    47  			links: []fsLink{
    48  				fsLink{
    49  					path: fsPath{"package", "link"},
    50  					to:   "_vendor",
    51  				},
    52  			},
    53  		},
    54  	}))
    55  
    56  	t.Run("vendor symlink to file", stripVendorTestCase(fsTestCase{
    57  		before: filesystemState{
    58  			files: []fsPath{
    59  				fsPath{"file"},
    60  			},
    61  			links: []fsLink{
    62  				fsLink{
    63  					path: fsPath{"vendor"},
    64  					to:   "file",
    65  				},
    66  			},
    67  		},
    68  		after: filesystemState{
    69  			files: []fsPath{
    70  				fsPath{"file"},
    71  			},
    72  			links: []fsLink{
    73  				fsLink{
    74  					path: fsPath{"vendor"},
    75  					to:   "file",
    76  				},
    77  			},
    78  		},
    79  	}))
    80  
    81  	t.Run("chained symlinks", stripVendorTestCase(fsTestCase{
    82  		before: filesystemState{
    83  			dirs: []fsPath{
    84  				fsPath{"_vendor"},
    85  			},
    86  			links: []fsLink{
    87  				fsLink{
    88  					path: fsPath{"vendor"},
    89  					to:   "vendor2",
    90  				},
    91  				fsLink{
    92  					path: fsPath{"vendor2"},
    93  					to:   "_vendor",
    94  				},
    95  			},
    96  		},
    97  		after: filesystemState{
    98  			dirs: []fsPath{
    99  				fsPath{"_vendor"},
   100  			},
   101  			links: []fsLink{
   102  				fsLink{
   103  					path: fsPath{"vendor2"},
   104  					to:   "_vendor",
   105  				},
   106  			},
   107  		},
   108  	}))
   109  
   110  	t.Run("circular symlinks", stripVendorTestCase(fsTestCase{
   111  		before: filesystemState{
   112  			dirs: []fsPath{
   113  				fsPath{"package"},
   114  			},
   115  			links: []fsLink{
   116  				fsLink{
   117  					path: fsPath{"package", "link1"},
   118  					to:   "link2",
   119  				},
   120  				fsLink{
   121  					path: fsPath{"package", "link2"},
   122  					to:   "link1",
   123  				},
   124  			},
   125  		},
   126  		after: filesystemState{
   127  			dirs: []fsPath{
   128  				fsPath{"package"},
   129  			},
   130  			links: []fsLink{
   131  				fsLink{
   132  					path: fsPath{"package", "link1"},
   133  					to:   "link2",
   134  				},
   135  				fsLink{
   136  					path: fsPath{"package", "link2"},
   137  					to:   "link1",
   138  				},
   139  			},
   140  		},
   141  	}))
   142  }