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

     1  package gps
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  )
     9  
    10  func stripVendorTestCase(tc fsTestCase) func(*testing.T) {
    11  	return func(t *testing.T) {
    12  		tempDir, err := ioutil.TempDir("", "TestStripVendor")
    13  		if err != nil {
    14  			t.Fatalf("ioutil.TempDir err=%q", err)
    15  		}
    16  		defer func() {
    17  			if err := os.RemoveAll(tempDir); err != nil {
    18  				t.Errorf("os.RemoveAll(%q) err=%q", tempDir, err)
    19  			}
    20  		}()
    21  		tc.before.root = tempDir
    22  		tc.after.root = tempDir
    23  
    24  		tc.before.setup(t)
    25  
    26  		if err := filepath.Walk(tempDir, stripVendor); err != nil {
    27  			t.Errorf("filepath.Walk err=%q", err)
    28  		}
    29  
    30  		tc.after.assert(t)
    31  	}
    32  }
    33  
    34  func TestStripVendorDirectory(t *testing.T) {
    35  	t.Run("vendor directory", stripVendorTestCase(fsTestCase{
    36  		before: filesystemState{
    37  			dirs: []fsPath{
    38  				fsPath{"package"},
    39  				fsPath{"package", "vendor"},
    40  			},
    41  		},
    42  		after: filesystemState{
    43  			dirs: []fsPath{
    44  				fsPath{"package"},
    45  			},
    46  		},
    47  	}))
    48  
    49  	t.Run("vendor file", stripVendorTestCase(fsTestCase{
    50  		before: filesystemState{
    51  			dirs: []fsPath{
    52  				fsPath{"package"},
    53  			},
    54  			files: []fsPath{
    55  				fsPath{"package", "vendor"},
    56  			},
    57  		},
    58  		after: filesystemState{
    59  			dirs: []fsPath{
    60  				fsPath{"package"},
    61  			},
    62  			files: []fsPath{
    63  				fsPath{"package", "vendor"},
    64  			},
    65  		},
    66  	}))
    67  }