@@ -7,6 +7,47 @@ import (
77 "github.com/twpayne/go-vfs/vfst"
88)
99
10+ func TestAddAfterModification (t * testing.T ) {
11+ c := & Config {
12+ SourceDir : "/home/user/.chezmoi" ,
13+ TargetDir : "/home/user" ,
14+ Umask : 022 ,
15+ DryRun : false ,
16+ Verbose : true ,
17+ }
18+ fs , cleanup , err := vfst .NewTestFS (map [string ]interface {}{
19+ "/home/user" : & vfst.Dir {Perm : 0755 },
20+ "/home/user/.chezmoi" : & vfst.Dir {Perm : 0700 },
21+ "/home/user/.bashrc" : "# contents of .bashrc\n " ,
22+ })
23+ defer cleanup ()
24+ if err != nil {
25+ t .Fatalf ("vfst.NewTestFS(_) == _, _, %v, want _, _, <nil>" , err )
26+ }
27+ args := []string {"/home/user/.bashrc" }
28+ if err := c .runAddCommand (fs , args ); err != nil {
29+ t .Errorf ("c.runAddCommand(fs, nil, %+v) == %v, want <nil>" , args , err )
30+ }
31+ vfst .RunTests (t , fs , "" ,
32+ vfst .TestPath ("/home/user/.chezmoi/dot_bashrc" ,
33+ vfst .TestModeIsRegular ,
34+ vfst .TestContentsString ("# contents of .bashrc\n " ),
35+ ),
36+ )
37+ if err := fs .WriteFile ("/home/user/.bashrc" , []byte ("# new contents of .bashrc\n " ), 0644 ); err != nil {
38+ t .Errorf ("fs.WriteFile(...) == %v, want <nil>" , err )
39+ }
40+ if err := c .runAddCommand (fs , args ); err != nil {
41+ t .Errorf ("c.runAddCommand(fs, nil, %+v) == %v, want <nil>" , args , err )
42+ }
43+ vfst .RunTests (t , fs , "" ,
44+ vfst .TestPath ("/home/user/.chezmoi/dot_bashrc" ,
45+ vfst .TestModeIsRegular ,
46+ vfst .TestContentsString ("# new contents of .bashrc\n " ),
47+ ),
48+ )
49+ }
50+
1051func TestAddCommand (t * testing.T ) {
1152 for _ , tc := range []struct {
1253 name string
@@ -234,44 +275,3 @@ func TestAddCommand(t *testing.T) {
234275 })
235276 }
236277}
237-
238- func TestAddAfterModification (t * testing.T ) {
239- c := & Config {
240- SourceDir : "/home/user/.chezmoi" ,
241- TargetDir : "/home/user" ,
242- Umask : 022 ,
243- DryRun : false ,
244- Verbose : true ,
245- }
246- fs , cleanup , err := vfst .NewTestFS (map [string ]interface {}{
247- "/home/user" : & vfst.Dir {Perm : 0755 },
248- "/home/user/.chezmoi" : & vfst.Dir {Perm : 0700 },
249- "/home/user/.bashrc" : "# contents of .bashrc\n " ,
250- })
251- defer cleanup ()
252- if err != nil {
253- t .Fatalf ("vfst.NewTestFS(_) == _, _, %v, want _, _, <nil>" , err )
254- }
255- args := []string {"/home/user/.bashrc" }
256- if err := c .runAddCommand (fs , args ); err != nil {
257- t .Errorf ("c.runAddCommand(fs, nil, %+v) == %v, want <nil>" , args , err )
258- }
259- vfst .RunTests (t , fs , "" ,
260- vfst .TestPath ("/home/user/.chezmoi/dot_bashrc" ,
261- vfst .TestModeIsRegular ,
262- vfst .TestContentsString ("# contents of .bashrc\n " ),
263- ),
264- )
265- if err := fs .WriteFile ("/home/user/.bashrc" , []byte ("# new contents of .bashrc\n " ), 0644 ); err != nil {
266- t .Errorf ("fs.WriteFile(...) == %v, want <nil>" , err )
267- }
268- if err := c .runAddCommand (fs , args ); err != nil {
269- t .Errorf ("c.runAddCommand(fs, nil, %+v) == %v, want <nil>" , args , err )
270- }
271- vfst .RunTests (t , fs , "" ,
272- vfst .TestPath ("/home/user/.chezmoi/dot_bashrc" ,
273- vfst .TestModeIsRegular ,
274- vfst .TestContentsString ("# new contents of .bashrc\n " ),
275- ),
276- )
277- }
0 commit comments