1
1
package cli_test
2
2
3
3
import (
4
+ "os"
5
+ "os/exec"
6
+ "path/filepath"
4
7
"testing"
5
8
6
9
"github.com/coder/coder/cli/clitest"
@@ -14,4 +17,58 @@ func TestDotfiles(t *testing.T) {
14
17
err := cmd .Execute ()
15
18
assert .Error (t , err )
16
19
})
20
+ t .Run ("NoInstallScript" , func (t * testing.T ) {
21
+ t .Parallel ()
22
+ _ , root := clitest .New (t )
23
+ testRepo := filepath .Join (string (root ), "test-repo" )
24
+ err := os .MkdirAll (testRepo , 0750 )
25
+ assert .NoError (t , err )
26
+ c := exec .Command ("git" , "init" )
27
+ c .Dir = testRepo
28
+ err = c .Run ()
29
+ assert .NoError (t , err )
30
+ err = os .WriteFile (filepath .Join (testRepo , ".bashrc" ), []byte ("wow" ), 0750 )
31
+ assert .NoError (t , err )
32
+ c = exec .Command ("git" , "add" , ".bashrc" )
33
+ c .Dir = testRepo
34
+ err = c .Run ()
35
+ assert .NoError (t , err )
36
+ c = exec .Command ("git" , "commit" , "-m" , `"add .bashrc"` )
37
+ c .Dir = testRepo
38
+ err = c .Run ()
39
+ assert .NoError (t , err )
40
+ cmd , _ := clitest .New (t , "dotfiles" , "--global-config" , string (root ), "--home-dir" , string (root ), "-y" , testRepo )
41
+ err = cmd .Execute ()
42
+ assert .NoError (t , err )
43
+ b , err := os .ReadFile (filepath .Join (string (root ), ".bashrc" ))
44
+ assert .NoError (t , err )
45
+ assert .Equal (t , string (b ), "wow" )
46
+ })
47
+ t .Run ("InstallScript" , func (t * testing.T ) {
48
+ t .Parallel ()
49
+ _ , root := clitest .New (t )
50
+ testRepo := filepath .Join (string (root ), "test-repo" )
51
+ err := os .MkdirAll (testRepo , 0750 )
52
+ assert .NoError (t , err )
53
+ c := exec .Command ("git" , "init" )
54
+ c .Dir = testRepo
55
+ err = c .Run ()
56
+ assert .NoError (t , err )
57
+ err = os .WriteFile (filepath .Join (testRepo , "install.sh" ), []byte ("#!/bin/bash\n echo wow > " + filepath .Join (string (root ), ".bashrc" )), 0750 )
58
+ assert .NoError (t , err )
59
+ c = exec .Command ("git" , "add" , "install.sh" )
60
+ c .Dir = testRepo
61
+ err = c .Run ()
62
+ assert .NoError (t , err )
63
+ c = exec .Command ("git" , "commit" , "-m" , `"add install.sh"` )
64
+ c .Dir = testRepo
65
+ err = c .Run ()
66
+ assert .NoError (t , err )
67
+ cmd , _ := clitest .New (t , "dotfiles" , "--global-config" , string (root ), "--home-dir" , string (root ), "-y" , testRepo )
68
+ err = cmd .Execute ()
69
+ assert .NoError (t , err )
70
+ b , err := os .ReadFile (filepath .Join (string (root ), ".bashrc" ))
71
+ assert .NoError (t , err )
72
+ assert .Equal (t , string (b ), "wow\n " )
73
+ })
17
74
}
0 commit comments