@@ -51,42 +51,109 @@ func TestMain(m *testing.M) {
51
51
os .Exit (m .Run ())
52
52
}
53
53
54
- func TestInstaller (t * testing.T ) {
55
- cmd := exec .Command ("sh" , flagInstallPath , "--skip-prompt" )
56
- cmd .Env = append (os .Environ (), "GOUP_UPDATE_ROOT=file://" + goupBinDir )
54
+ func TestGoup (t * testing.T ) {
55
+ t .Run ("installer" , func (t * testing.T ) {
56
+ cmd := exec .Command ("sh" , flagInstallPath , "--skip-prompt" )
57
+ cmd .Env = append (os .Environ (), "GOUP_UPDATE_ROOT=file://" + goupBinDir )
58
+ execCmd (t , cmd )
59
+
60
+ // check file exists
61
+ filesShouldExist := []string {
62
+ commands .GoupDir (),
63
+ commands .GoupEnvFile (),
64
+ commands .GoupBinDir (),
65
+ commands .GoupCurrentDir (),
66
+ commands .GoupCurrentBinDir (),
67
+ }
68
+ for _ , f := range filesShouldExist {
69
+ if _ , err := os .Stat (f ); os .IsNotExist (err ) {
70
+ t .Error (err )
71
+ }
72
+ }
57
73
58
- out , err := cmd .CombinedOutput ()
59
- if err != nil {
60
- t .Fatalf ("%s: %s" , out , err )
61
- }
74
+ // check profiles
75
+ for _ , f := range commands .ProfileFiles {
76
+ ok , err := fileContains (f , commands .ProfileFileSourceContent )
77
+ if err != nil {
78
+ t .Error (err )
79
+ }
80
+
81
+ if ! ok {
82
+ t .Errorf ("%s does not source goup" , f )
83
+ }
84
+ }
85
+ })
62
86
63
- fmt . Println ( string ( out ) )
87
+ goupBin := filepath . Join ( commands . GoupBinDir (), "goup" )
64
88
65
- // check file exists
66
- filesShouldExist := [] string {
67
- commands . GoupDir (),
68
- commands . GoupEnvFile (),
69
- commands . GoupBinDir (),
70
- commands . GoupCurrentDir (),
71
- commands . GoupCurrentBinDir (),
72
- }
73
- for _ , f := range filesShouldExist {
74
- if _ , err := os . Stat ( f ); os . IsNotExist ( err ) {
75
- t .Error ( err )
89
+ t . Run ( "goup install" , func ( t * testing. T ) {
90
+ cmd := exec . Command ( goupBin , "install" , "1.15.2" )
91
+ execCmd ( t , cmd )
92
+ })
93
+
94
+ t . Run ( "goup show" , func ( t * testing. T ) {
95
+ cmd := exec . Command ( goupBin , "show" )
96
+ out := execCmd ( t , cmd )
97
+
98
+ if want , got := [] byte ( "1.15.2" ), out ; ! bytes . Contains ( got , want ) {
99
+ t .Fatalf ( "goup show failed: want=%s got=%s" , want , out )
76
100
}
77
- }
101
+ })
102
+
103
+ t .Run ("goup ls-ver" , func (t * testing.T ) {
104
+ cmd := exec .Command (goupBin , "ls-ver" )
105
+ out := execCmd (t , cmd )
106
+
107
+ if want , got := []byte ("1.15.2" ), out ; ! bytes .Contains (got , want ) {
108
+ t .Fatalf ("goup ls-ver failed: want=%s got=%s" , want , out )
109
+ }
110
+ })
111
+
112
+ t .Run ("goup remove" , func (t * testing.T ) {
113
+ cmd := exec .Command (goupBin , "remove" , "1.15.2" )
114
+ execCmd (t , cmd )
115
+ })
78
116
79
- // check profiles
80
- for _ , f := range commands .ProfileFiles {
81
- ok , err := fileContains (f , commands .ProfileFileSourceContent )
117
+ t .Run ("goup show again" , func (t * testing.T ) {
118
+ cmd := exec .Command (goupBin , "show" )
119
+ out := execCmd (t , cmd )
120
+
121
+ if want , got := []byte ("1.15.2" ), out ; bytes .Contains (got , want ) {
122
+ t .Fatalf ("goup show again failed: want=%s got=%s" , want , out )
123
+ }
124
+ })
125
+
126
+ t .Run ("goup upgrade" , func (t * testing.T ) {
127
+ cmd := exec .Command (goupBin , "upgrade" , "0.1.4" )
128
+ cmd .Env = append (os .Environ (), fmt .Sprintf ("PATH=%s:$PATH" , filepath .Dir (goupBin )))
129
+ out , err := cmd .CombinedOutput ()
82
130
if err != nil {
83
- t .Error ( err )
131
+ t .Fatalf ( "goup upgrade failed: %s: %s" , out , err )
84
132
}
133
+ t .Logf ("%s" , out )
134
+ })
135
+
136
+ t .Run ("goup version" , func (t * testing.T ) {
137
+ cmd := exec .Command (goupBin , "version" )
138
+ out := execCmd (t , cmd )
85
139
86
- if ! ok {
87
- t .Errorf ( "%s does not source goup " , f )
140
+ if want , got := [] byte ( "0.1.4" ), out ; ! bytes . Contains ( got , want ) {
141
+ t .Fatalf ( "goup version failed: want=%s got=%s " , want , out )
88
142
}
143
+ })
144
+
145
+ }
146
+
147
+ func execCmd (t * testing.T , cmd * exec.Cmd ) []byte {
148
+ t .Helper ()
149
+
150
+ out , err := cmd .CombinedOutput ()
151
+ if err != nil {
152
+ t .Fatalf ("%s: %s" , out , err )
89
153
}
154
+ t .Logf ("%s" , out )
155
+
156
+ return out
90
157
}
91
158
92
159
func fileContains (f string , s string ) (bool , error ) {
0 commit comments