gopkg.in/tools/godep.v73@v73.0.0-20160531225236-f4edf338389e/update_test.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  	"log"
     7  	"os"
     8  	"path/filepath"
     9  	"reflect"
    10  	"testing"
    11  )
    12  
    13  func TestUpdate(t *testing.T) {
    14  	var cases = []struct {
    15  		cwd    string
    16  		args   []string
    17  		vendor bool
    18  		start  []*node
    19  		want   []*node
    20  		wdep   Godeps
    21  		werr   bool
    22  	}{
    23  		{ // 0 - simple case, update one dependency
    24  			cwd:  "C",
    25  			args: []string{"D"},
    26  			start: []*node{
    27  				{
    28  					"D",
    29  					"",
    30  					[]*node{
    31  						{"main.go", pkg("D") + decl("D1"), nil},
    32  						{"+git", "D1", nil},
    33  						{"main.go", pkg("D") + decl("D2"), nil},
    34  						{"+git", "D2", nil},
    35  					},
    36  				},
    37  				{
    38  					"C",
    39  					"",
    40  					[]*node{
    41  						{"main.go", pkg("main", "D"), nil},
    42  						{"Godeps/Godeps.json", godeps("C", "D", "D1"), nil},
    43  						{"Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
    44  						{"+git", "", nil},
    45  					},
    46  				},
    47  			},
    48  			want: []*node{
    49  				{"C/Godeps/_workspace/src/D/main.go", pkg("D") + decl("D2"), nil},
    50  			},
    51  			wdep: Godeps{
    52  				ImportPath: "C",
    53  				Deps: []Dependency{
    54  					{ImportPath: "D", Comment: "D2"},
    55  				},
    56  			},
    57  		},
    58  		{ // 1 - simple case, update one dependency, trailing slash
    59  			cwd:  "C",
    60  			args: []string{"D/"},
    61  			start: []*node{
    62  				{
    63  					"D",
    64  					"",
    65  					[]*node{
    66  						{"main.go", pkg("D") + decl("D1"), nil},
    67  						{"+git", "D1", nil},
    68  						{"main.go", pkg("D") + decl("D2"), nil},
    69  						{"+git", "D2", nil},
    70  					},
    71  				},
    72  				{
    73  					"C",
    74  					"",
    75  					[]*node{
    76  						{"main.go", pkg("main", "D"), nil},
    77  						{"Godeps/Godeps.json", godeps("C", "D", "D1"), nil},
    78  						{"Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
    79  						{"+git", "", nil},
    80  					},
    81  				},
    82  			},
    83  			want: []*node{
    84  				{"C/Godeps/_workspace/src/D/main.go", pkg("D") + decl("D2"), nil},
    85  			},
    86  			wdep: Godeps{
    87  				ImportPath: "C",
    88  				Deps: []Dependency{
    89  					{ImportPath: "D", Comment: "D2"},
    90  				},
    91  			},
    92  		},
    93  		{ // 2 - update one dependency, keep other one, no rewrite
    94  			cwd:  "C",
    95  			args: []string{"D"},
    96  			start: []*node{
    97  				{
    98  					"D",
    99  					"",
   100  					[]*node{
   101  						{"main.go", pkg("D", "E") + decl("D1"), nil},
   102  						{"+git", "D1", nil},
   103  						{"main.go", pkg("D", "E") + decl("D2"), nil},
   104  						{"+git", "D2", nil},
   105  					},
   106  				},
   107  				{
   108  					"E",
   109  					"",
   110  					[]*node{
   111  						{"main.go", pkg("E") + decl("E1"), nil},
   112  						{"+git", "E1", nil},
   113  						{"main.go", pkg("E") + decl("E2"), nil},
   114  						{"+git", "E2", nil},
   115  					},
   116  				},
   117  				{
   118  					"C",
   119  					"",
   120  					[]*node{
   121  						{"main.go", pkg("main", "D", "E"), nil},
   122  						{"Godeps/Godeps.json", godeps("C", "D", "D1", "E", "E1"), nil},
   123  						{"Godeps/_workspace/src/D/main.go", pkg("D", "E") + decl("D1"), nil},
   124  						{"Godeps/_workspace/src/E/main.go", pkg("E") + decl("E1"), nil},
   125  						{"+git", "", nil},
   126  					},
   127  				},
   128  			},
   129  			want: []*node{
   130  				{"C/Godeps/_workspace/src/D/main.go", pkg("D", "E") + decl("D2"), nil},
   131  				{"C/Godeps/_workspace/src/E/main.go", pkg("E") + decl("E1"), nil},
   132  			},
   133  			wdep: Godeps{
   134  				ImportPath: "C",
   135  				Deps: []Dependency{
   136  					{ImportPath: "D", Comment: "D2"},
   137  					{ImportPath: "E", Comment: "E1"},
   138  				},
   139  			},
   140  		},
   141  		{ // 3 - update one dependency, keep other one, with rewrite
   142  			cwd:  "C",
   143  			args: []string{"D"},
   144  			start: []*node{
   145  				{
   146  					"D",
   147  					"",
   148  					[]*node{
   149  						{"main.go", pkg("D", "E") + decl("D1"), nil},
   150  						{"+git", "D1", nil},
   151  						{"main.go", pkg("D", "E") + decl("D2"), nil},
   152  						{"+git", "D2", nil},
   153  					},
   154  				},
   155  				{
   156  					"E",
   157  					"",
   158  					[]*node{
   159  						{"main.go", pkg("E") + decl("E1"), nil},
   160  						{"+git", "E1", nil},
   161  						{"main.go", pkg("E") + decl("E2"), nil},
   162  						{"+git", "E2", nil},
   163  					},
   164  				},
   165  				{
   166  					"C",
   167  					"",
   168  					[]*node{
   169  						{"main.go", pkg("main", "C/Godeps/_workspace/src/D", "C/Godeps/_workspace/src/E"), nil},
   170  						{"Godeps/Godeps.json", godeps("C", "D", "D1", "E", "E1"), nil},
   171  						{"Godeps/_workspace/src/D/main.go", pkg("D", "C/Godeps/_workspace/src/E") + decl("D1"), nil},
   172  						{"Godeps/_workspace/src/E/main.go", pkg("E") + decl("E1"), nil},
   173  						{"+git", "", nil},
   174  					},
   175  				},
   176  			},
   177  			want: []*node{
   178  				{"C/main.go", pkg("main", "C/Godeps/_workspace/src/D", "C/Godeps/_workspace/src/E"), nil},
   179  				{"C/Godeps/_workspace/src/D/main.go", pkg("D", "C/Godeps/_workspace/src/E") + "\n" + decl("D2"), nil},
   180  				{"C/Godeps/_workspace/src/E/main.go", pkg("E") + decl("E1"), nil},
   181  			},
   182  			wdep: Godeps{
   183  				ImportPath: "C",
   184  				Deps: []Dependency{
   185  					{ImportPath: "D", Comment: "D2"},
   186  					{ImportPath: "E", Comment: "E1"},
   187  				},
   188  			},
   189  		},
   190  		{ // 4 - update all dependencies
   191  			cwd:  "C",
   192  			args: []string{"..."},
   193  			start: []*node{
   194  				{
   195  					"D",
   196  					"",
   197  					[]*node{
   198  						{"main.go", pkg("D") + decl("D1"), nil},
   199  						{"+git", "D1", nil},
   200  						{"main.go", pkg("D") + decl("D2"), nil},
   201  						{"+git", "D2", nil},
   202  					},
   203  				},
   204  				{
   205  					"E",
   206  					"",
   207  					[]*node{
   208  						{"main.go", pkg("E") + decl("E1"), nil},
   209  						{"+git", "E1", nil},
   210  						{"main.go", pkg("E") + decl("E2"), nil},
   211  						{"+git", "E2", nil},
   212  					},
   213  				},
   214  				{
   215  					"C",
   216  					"",
   217  					[]*node{
   218  						{"main.go", pkg("main", "D", "E"), nil},
   219  						{"Godeps/Godeps.json", godeps("C", "D", "D1", "E", "E1"), nil},
   220  						{"Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
   221  						{"Godeps/_workspace/src/E/main.go", pkg("E") + decl("E1"), nil},
   222  						{"+git", "", nil},
   223  					},
   224  				},
   225  			},
   226  			want: []*node{
   227  				{"C/Godeps/_workspace/src/D/main.go", pkg("D") + decl("D2"), nil},
   228  				{"C/Godeps/_workspace/src/E/main.go", pkg("E") + decl("E2"), nil},
   229  			},
   230  			wdep: Godeps{
   231  				ImportPath: "C",
   232  				Deps: []Dependency{
   233  					{ImportPath: "D", Comment: "D2"},
   234  					{ImportPath: "E", Comment: "E2"},
   235  				},
   236  			},
   237  		},
   238  		{ // 5 - one match of two patterns
   239  			cwd:  "C",
   240  			args: []string{"D", "X"},
   241  			start: []*node{
   242  				{
   243  					"D",
   244  					"",
   245  					[]*node{
   246  						{"main.go", pkg("D") + decl("D1"), nil},
   247  						{"+git", "D1", nil},
   248  						{"main.go", pkg("D") + decl("D2"), nil},
   249  						{"+git", "D2", nil},
   250  					},
   251  				},
   252  				{
   253  					"C",
   254  					"",
   255  					[]*node{
   256  						{"main.go", pkg("main", "D"), nil},
   257  						{"Godeps/Godeps.json", godeps("C", "D", "D1"), nil},
   258  						{"Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
   259  						{"+git", "", nil},
   260  					},
   261  				},
   262  			},
   263  			want: []*node{
   264  				{"C/Godeps/_workspace/src/D/main.go", pkg("D") + decl("D2"), nil},
   265  			},
   266  			wdep: Godeps{
   267  				ImportPath: "C",
   268  				Deps: []Dependency{
   269  					{ImportPath: "D", Comment: "D2"},
   270  				},
   271  			},
   272  		},
   273  		{ // 6 - no matches
   274  			cwd:  "C",
   275  			args: []string{"X"},
   276  			start: []*node{
   277  				{
   278  					"D",
   279  					"",
   280  					[]*node{
   281  						{"main.go", pkg("D") + decl("D1"), nil},
   282  						{"+git", "D1", nil},
   283  						{"main.go", pkg("D") + decl("D2"), nil},
   284  						{"+git", "D2", nil},
   285  					},
   286  				},
   287  				{
   288  					"C",
   289  					"",
   290  					[]*node{
   291  						{"main.go", pkg("main", "D"), nil},
   292  						{"Godeps/Godeps.json", godeps("C", "D", "D1"), nil},
   293  						{"Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
   294  						{"+git", "", nil},
   295  					},
   296  				},
   297  			},
   298  			want: []*node{
   299  				{"C/Godeps/_workspace/src/D/main.go", pkg("D") + decl("D1"), nil},
   300  			},
   301  			wdep: Godeps{
   302  				ImportPath: "C",
   303  				Deps: []Dependency{
   304  					{ImportPath: "D", Comment: "D1"},
   305  				},
   306  			},
   307  			werr: true,
   308  		},
   309  		{ // 7 - update just one package of two in a repo skips it
   310  			cwd:  "C",
   311  			args: []string{"D/A", "E"},
   312  			start: []*node{
   313  				{
   314  					"D",
   315  					"",
   316  					[]*node{
   317  						{"A/main.go", pkg("A") + decl("D1"), nil},
   318  						{"B/main.go", pkg("B") + decl("D1"), nil},
   319  						{"+git", "D1", nil},
   320  						{"A/main.go", pkg("A") + decl("D2"), nil},
   321  						{"B/main.go", pkg("B") + decl("D2"), nil},
   322  						{"+git", "D2", nil},
   323  					},
   324  				},
   325  				{
   326  					"E",
   327  					"",
   328  					[]*node{
   329  						{"main.go", pkg("E") + decl("E1"), nil},
   330  						{"+git", "E1", nil},
   331  						{"main.go", pkg("E") + decl("E2"), nil},
   332  						{"+git", "E2", nil},
   333  					},
   334  				},
   335  				{
   336  					"C",
   337  					"",
   338  					[]*node{
   339  						{"main.go", pkg("main", "D/A", "D/B", "E"), nil},
   340  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1", "E", "E1"), nil},
   341  						{"Godeps/_workspace/src/D/A/main.go", pkg("A") + decl("D1"), nil},
   342  						{"Godeps/_workspace/src/D/B/main.go", pkg("B") + decl("D1"), nil},
   343  						{"Godeps/_workspace/src/E/main.go", pkg("E") + decl("E1"), nil},
   344  						{"+git", "", nil},
   345  					},
   346  				},
   347  			},
   348  			want: []*node{
   349  				{"C/Godeps/_workspace/src/D/A/main.go", pkg("A") + decl("D1"), nil},
   350  				{"C/Godeps/_workspace/src/D/B/main.go", pkg("B") + decl("D1"), nil},
   351  				{"C/Godeps/_workspace/src/E/main.go", pkg("E") + decl("E2"), nil},
   352  			},
   353  			wdep: Godeps{
   354  				ImportPath: "C",
   355  				Deps: []Dependency{
   356  					{ImportPath: "D/A", Comment: "D1"},
   357  					{ImportPath: "D/B", Comment: "D1"},
   358  					{ImportPath: "E", Comment: "E2"},
   359  				},
   360  			},
   361  		},
   362  		{ // 8 - update just one package of two in a repo, none left
   363  			cwd:  "C",
   364  			args: []string{"D/A"},
   365  			start: []*node{
   366  				{
   367  					"D",
   368  					"",
   369  					[]*node{
   370  						{"A/main.go", pkg("A") + decl("D1"), nil},
   371  						{"B/main.go", pkg("B") + decl("D1"), nil},
   372  						{"+git", "D1", nil},
   373  						{"A/main.go", pkg("A") + decl("D2"), nil},
   374  						{"B/main.go", pkg("B") + decl("D2"), nil},
   375  						{"+git", "D2", nil},
   376  					},
   377  				},
   378  				{
   379  					"C",
   380  					"",
   381  					[]*node{
   382  						{"main.go", pkg("main", "D/A", "D/B"), nil},
   383  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
   384  						{"Godeps/_workspace/src/D/A/main.go", pkg("A") + decl("D1"), nil},
   385  						{"Godeps/_workspace/src/D/B/main.go", pkg("B") + decl("D1"), nil},
   386  						{"+git", "", nil},
   387  					},
   388  				},
   389  			},
   390  			want: []*node{
   391  				{"C/Godeps/_workspace/src/D/A/main.go", pkg("A") + decl("D1"), nil},
   392  				{"C/Godeps/_workspace/src/D/B/main.go", pkg("B") + decl("D1"), nil},
   393  			},
   394  			wdep: Godeps{
   395  				ImportPath: "C",
   396  				Deps: []Dependency{
   397  					{ImportPath: "D/A", Comment: "D1"},
   398  					{ImportPath: "D/B", Comment: "D1"},
   399  				},
   400  			},
   401  			werr: true,
   402  		},
   403  		{ // 9 - package/..., just version bump
   404  			vendor: true,
   405  			cwd:    "C",
   406  			args:   []string{"D/..."},
   407  			start: []*node{
   408  				{
   409  					"D",
   410  					"",
   411  					[]*node{
   412  						{"A/main.go", pkg("A") + decl("D1"), nil},
   413  						{"B/main.go", pkg("B") + decl("D1"), nil},
   414  						{"+git", "D1", nil},
   415  						{"A/main.go", pkg("A") + decl("D2"), nil},
   416  						{"B/main.go", pkg("B") + decl("D2"), nil},
   417  						{"+git", "D2", nil},
   418  					},
   419  				},
   420  				{
   421  					"C",
   422  					"",
   423  					[]*node{
   424  						{"main.go", pkg("main", "D/A", "D/B"), nil},
   425  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
   426  						{"vendor/D/A/main.go", pkg("A") + decl("D1"), nil},
   427  						{"vendor/D/B/main.go", pkg("B") + decl("D1"), nil},
   428  						{"+git", "", nil},
   429  					},
   430  				},
   431  			},
   432  			want: []*node{
   433  				{"C/vendor/D/A/main.go", pkg("A") + decl("D2"), nil},
   434  				{"C/vendor/D/B/main.go", pkg("B") + decl("D2"), nil},
   435  			},
   436  			wdep: Godeps{
   437  				ImportPath: "C",
   438  				Deps: []Dependency{
   439  					{ImportPath: "D/A", Comment: "D2"},
   440  					{ImportPath: "D/B", Comment: "D2"},
   441  				},
   442  			},
   443  		},
   444  		{ // 10 - package/..., new unrelated package that's not imported
   445  			vendor: true,
   446  			cwd:    "C",
   447  			args:   []string{"D/..."},
   448  			start: []*node{
   449  				{
   450  					"D",
   451  					"",
   452  					[]*node{
   453  						{"A/main.go", pkg("A") + decl("D1"), nil},
   454  						{"B/main.go", pkg("B") + decl("D1"), nil},
   455  						{"+git", "D1", nil},
   456  						{"A/main.go", pkg("A") + decl("D2"), nil},
   457  						{"B/main.go", pkg("B") + decl("D2"), nil},
   458  						{"E/main.go", pkg("E") + decl("D2"), nil},
   459  						{"+git", "D2", nil},
   460  					},
   461  				},
   462  				{
   463  					"C",
   464  					"",
   465  					[]*node{
   466  						{"main.go", pkg("main", "D/A", "D/B"), nil},
   467  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
   468  						{"vendor/D/A/main.go", pkg("A") + decl("D1"), nil},
   469  						{"vendor/D/B/main.go", pkg("B") + decl("D1"), nil},
   470  						{"+git", "", nil},
   471  					},
   472  				},
   473  			},
   474  			want: []*node{
   475  				{"C/vendor/D/A/main.go", pkg("A") + decl("D2"), nil},
   476  				{"C/vendor/D/B/main.go", pkg("B") + decl("D2"), nil},
   477  				{"C/vendor/D/E/main.go", "(absent)", nil},
   478  			},
   479  			wdep: Godeps{
   480  				ImportPath: "C",
   481  				Deps: []Dependency{
   482  					{ImportPath: "D/A", Comment: "D2"},
   483  					{ImportPath: "D/B", Comment: "D2"},
   484  				},
   485  			},
   486  		},
   487  		{ // 11 - package/..., new transitive package, same repo
   488  			vendor: true,
   489  			cwd:    "C",
   490  			args:   []string{"D/..."},
   491  			start: []*node{
   492  				{
   493  					"D",
   494  					"",
   495  					[]*node{
   496  						{"A/main.go", pkg("A") + decl("D1"), nil},
   497  						{"B/main.go", pkg("B") + decl("D1"), nil},
   498  						{"+git", "D1", nil},
   499  						{"A/main.go", pkg("A") + decl("D2"), nil},
   500  						{"B/main.go", pkg("B", "D/E") + decl("D2"), nil},
   501  						{"E/main.go", pkg("E") + decl("D2"), nil},
   502  						{"+git", "D2", nil},
   503  					},
   504  				},
   505  				{
   506  					"C",
   507  					"",
   508  					[]*node{
   509  						{"main.go", pkg("main", "D/A", "D/B"), nil},
   510  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
   511  						{"vendor/D/A/main.go", pkg("A") + decl("D1"), nil},
   512  						{"vendor/D/B/main.go", pkg("B") + decl("D1"), nil},
   513  						{"+git", "", nil},
   514  					},
   515  				},
   516  			},
   517  			want: []*node{
   518  				{"C/vendor/D/A/main.go", pkg("A") + decl("D2"), nil},
   519  				{"C/vendor/D/B/main.go", pkg("B", "D/E") + decl("D2"), nil},
   520  				{"C/vendor/D/E/main.go", pkg("E") + decl("D2"), nil},
   521  			},
   522  			wdep: Godeps{
   523  				ImportPath: "C",
   524  				Deps: []Dependency{
   525  					{ImportPath: "D/A", Comment: "D2"},
   526  					{ImportPath: "D/B", Comment: "D2"},
   527  					{ImportPath: "D/E", Comment: "D2"},
   528  				},
   529  			},
   530  		},
   531  		{ // 12 - package/..., new transitive package, different repo
   532  			vendor: true,
   533  			cwd:    "C",
   534  			args:   []string{"D/..."},
   535  			start: []*node{
   536  				{
   537  					"D",
   538  					"",
   539  					[]*node{
   540  						{"A/main.go", pkg("A") + decl("D1"), nil},
   541  						{"B/main.go", pkg("B") + decl("D1"), nil},
   542  						{"+git", "D1", nil},
   543  						{"A/main.go", pkg("A") + decl("D2"), nil},
   544  						{"B/main.go", pkg("B", "E") + decl("D2"), nil},
   545  						{"+git", "D2", nil},
   546  					},
   547  				},
   548  				{
   549  					"E",
   550  					"",
   551  					[]*node{
   552  						{"main.go", pkg("E") + decl("E1"), nil},
   553  						{"+git", "E1", nil},
   554  					},
   555  				},
   556  				{
   557  					"C",
   558  					"",
   559  					[]*node{
   560  						{"main.go", pkg("main", "D/A", "D/B"), nil},
   561  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
   562  						{"vendor/D/A/main.go", pkg("A") + decl("D1"), nil},
   563  						{"vendor/D/B/main.go", pkg("B") + decl("D1"), nil},
   564  						{"+git", "", nil},
   565  					},
   566  				},
   567  			},
   568  			want: []*node{
   569  				{"C/vendor/D/A/main.go", pkg("A") + decl("D2"), nil},
   570  				{"C/vendor/D/B/main.go", pkg("B", "E") + decl("D2"), nil},
   571  				{"C/vendor/E/main.go", pkg("E") + decl("E1"), nil},
   572  			},
   573  			wdep: Godeps{
   574  				ImportPath: "C",
   575  				Deps: []Dependency{
   576  					{ImportPath: "D/A", Comment: "D2"},
   577  					{ImportPath: "D/B", Comment: "D2"},
   578  					{ImportPath: "E", Comment: "E1"},
   579  				},
   580  			},
   581  		},
   582  		{ // 13 - package/..., missing packages
   583  			vendor: true,
   584  			cwd:    "C",
   585  			args:   []string{"D/..."},
   586  			start: []*node{
   587  				{
   588  					"D",
   589  					"",
   590  					[]*node{
   591  						{"A/main.go", pkg("A") + decl("D1"), nil},
   592  						{"B/main.go", pkg("B") + decl("D1"), nil},
   593  						{"+git", "D1", nil},
   594  					},
   595  				},
   596  				{
   597  					"C",
   598  					"",
   599  					[]*node{
   600  						{"main.go", pkg("main", "D/A"), nil},
   601  						{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
   602  						{"vendor/D/A/main.go", pkg("A") + decl("D1"), nil},
   603  						{"vendor/D/B/main.go", pkg("B") + decl("D1"), nil},
   604  						{"+git", "", nil},
   605  					},
   606  				},
   607  				{"D",
   608  					"",
   609  					[]*node{
   610  						{"A/main.go", pkg("A") + decl("D2"), nil},
   611  						{"B", "(rm)", nil},
   612  						{"+git", "D2", nil},
   613  					},
   614  				},
   615  			},
   616  			want: []*node{
   617  				{"C/vendor/D/A/main.go", pkg("A") + decl("D2"), nil},
   618  				{"C/vendor/D/B/main.go", "(absent)", nil},
   619  				{"C/vendor/D/E/main.go", "(absent)", nil},
   620  			},
   621  			wdep: Godeps{
   622  				ImportPath: "C",
   623  				Deps: []Dependency{
   624  					{ImportPath: "D/A", Comment: "D2"},
   625  				},
   626  			},
   627  		},
   628  		{ // 14 - Update package A, but not package B, which is missing from $GOPATH
   629  			vendor: true,
   630  			cwd:    "C",
   631  			args:   []string{"A"},
   632  			start: []*node{
   633  				{
   634  					"A",
   635  					"",
   636  					[]*node{
   637  						{"main.go", pkg("A") + decl("A1"), nil},
   638  						{"+git", "A1", nil},
   639  						{"main.go", pkg("A") + decl("A2"), nil},
   640  						{"+git", "A2", nil},
   641  					},
   642  				},
   643  				{ // Create B so makeTree can resolve the rev for Godeps.json
   644  					"B",
   645  					"",
   646  					[]*node{
   647  						{"main.go", pkg("B") + decl("B1"), nil},
   648  						{"+git", "B1", nil},
   649  					},
   650  				},
   651  				{
   652  					"C",
   653  					"",
   654  					[]*node{
   655  						{"main.go", pkg("main", "A", "B"), nil},
   656  						{"Godeps/Godeps.json", godeps("C", "A", "A1", "B", "B1"), nil},
   657  						{"vendor/A/main.go", pkg("A") + decl("A1"), nil},
   658  						{"vendor/B/main.go", pkg("B") + decl("B1"), nil},
   659  						{"+git", "", nil},
   660  					},
   661  				},
   662  				{ // Remove B so it's not in the $GOPATH
   663  					"",
   664  					"",
   665  					[]*node{
   666  						{"B", "(rm)", nil},
   667  					},
   668  				},
   669  			},
   670  			want: []*node{
   671  				{"C/vendor/A/main.go", pkg("A") + decl("A2"), nil},
   672  				{"C/vendor/B/main.go", pkg("B") + decl("B1"), nil},
   673  			},
   674  			wdep: Godeps{
   675  				ImportPath: "C",
   676  				Deps: []Dependency{
   677  					{ImportPath: "A", Comment: "A2"},
   678  					{ImportPath: "B", Comment: "B1"},
   679  				},
   680  			},
   681  		},
   682  	}
   683  
   684  	wd, err := os.Getwd()
   685  	if err != nil {
   686  		t.Fatal(err)
   687  	}
   688  	const gopath = "godeptest"
   689  	defer os.RemoveAll(gopath)
   690  	for pos, test := range cases {
   691  		setGlobals(test.vendor)
   692  		err = os.RemoveAll(gopath)
   693  		if err != nil {
   694  			t.Fatal(err)
   695  		}
   696  		src := filepath.Join(gopath, "src")
   697  		makeTree(t, &node{src, "", test.start}, "")
   698  
   699  		dir := filepath.Join(wd, src, test.cwd)
   700  		err = os.Chdir(dir)
   701  		if err != nil {
   702  			panic(err)
   703  		}
   704  		setGOPATH(filepath.Join(wd, gopath))
   705  		log.SetOutput(ioutil.Discard)
   706  		err = update(test.args)
   707  		log.SetOutput(os.Stderr)
   708  		if err != nil {
   709  			t.Log(pos, "Err:", err)
   710  		}
   711  		if g := err != nil; g != test.werr {
   712  			t.Errorf("update err = %v (%v) want %v", g, err, test.werr)
   713  		}
   714  		err = os.Chdir(wd)
   715  		if err != nil {
   716  			panic(err)
   717  		}
   718  
   719  		checkTree(t, pos, &node{src, "", test.want})
   720  
   721  		f, err := os.Open(filepath.Join(dir, "Godeps/Godeps.json"))
   722  		if err != nil {
   723  			t.Error(err)
   724  		}
   725  		g := new(Godeps)
   726  		err = json.NewDecoder(f).Decode(g)
   727  		if err != nil {
   728  			t.Error(err)
   729  		}
   730  		f.Close()
   731  
   732  		if g.ImportPath != test.wdep.ImportPath {
   733  			t.Errorf("ImportPath = %s want %s", g.ImportPath, test.wdep.ImportPath)
   734  		}
   735  		for i := range g.Deps {
   736  			g.Deps[i].Rev = ""
   737  		}
   738  		if !reflect.DeepEqual(g.Deps, test.wdep.Deps) {
   739  			t.Errorf("Deps = %v want %v", g.Deps, test.wdep.Deps)
   740  		}
   741  	}
   742  }