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

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