@@ -19,98 +19,75 @@ package homebrew
19
19
20
20
import (
21
21
"fmt"
22
- "github.com/golang/mock/gomock"
23
- "github.com/mongodb/mongocli/internal/mocks"
24
22
"testing"
23
+ "time"
25
24
26
- "github.com/mongodb/mongocli/internal/config"
27
25
"github.com/spf13/afero"
28
26
)
29
27
30
- func TestFile (t * testing.T ) {
31
- t .Run ("save brewpath mcli" , func (t * testing.T ) {
32
- appFS := afero .NewMemMapFs ()
33
- s := NewLoaderSaver (appFS , "mongocli" )
34
-
35
- err := s .SaveBrewPath ("a/b/c" , "d/e/f" )
36
- if err != nil {
37
- t .Errorf ("LoadLatestVersion() unexpected error: %v" , err )
38
- }
39
- })
40
- t .Run ("load brewpath mcli" , func (t * testing.T ) {
41
- appFS := afero .NewMemMapFs ()
42
- s := NewLoaderSaver (appFS , "mongocli" )
43
-
44
- path , _ := config .Path (brewFileSubPath )
45
- _ = afero .WriteFile (appFS , path , []byte ("" ), 0600 )
46
-
47
- p1 , p2 , err := s .LoadBrewPath ()
48
- if err != nil || p1 != "" || p2 != "" {
49
- t .Errorf ("LoadLatestVersion() unexpected error: %v" , err )
50
- }
51
- })
52
- t .Run ("load brewpath mcli is empty" , func (t * testing.T ) {
53
- appFS := afero .NewMemMapFs ()
54
- s := NewLoaderSaver (appFS , "mongocli" )
55
-
56
- _ , _ , err := s .LoadBrewPath ()
57
- if err == nil {
58
- t .Errorf ("LoadLatestVersion() expected error: file not found" )
59
- }
60
- })
61
- t .Run ("save brewpath atlascli" , func (t * testing.T ) {
62
- appFS := afero .NewMemMapFs ()
63
- s := NewLoaderSaver (appFS , "atlascli" )
64
-
65
- err := s .SaveBrewPath ("a/b/c" , "d/e/f" )
66
- if err != nil {
67
- t .Errorf ("LoadLatestVersion() unexpected error: %v" , err )
68
- }
69
- })
70
- t .Run ("load brewpath atlascli" , func (t * testing.T ) {
71
- appFS := afero .NewMemMapFs ()
72
- s := NewLoaderSaver (appFS , "atlascli" )
73
-
74
- path , _ := config .Path (brewFileSubPath )
75
- _ = afero .WriteFile (appFS , path , []byte ("" ), 0600 )
76
-
77
- p1 , p2 , err := s .LoadBrewPath ()
78
- if err != nil || p1 != "" || p2 != "" {
79
- t .Errorf ("LoadLatestVersion() unexpected error: %v" , err )
80
- }
81
- })
82
- t .Run ("load brewpath atlascli is empty" , func (t * testing.T ) {
83
- appFS := afero .NewMemMapFs ()
84
- s := NewLoaderSaver (appFS , "atlascli" )
85
-
86
- _ , _ , err := s .LoadBrewPath ()
87
- if err == nil {
88
- t .Errorf ("LoadLatestVersion() expected error: file not found" )
89
- }
90
- })
91
- }
92
-
93
- func TestOutputOpts_testIsHomebrew (t * testing.T ) {
28
+ func TestChecker_IsHomebrew (t * testing.T ) {
94
29
tests := []struct {
95
- tool string
96
- isHb bool
30
+ paths * homebrew
31
+ isHomebrew bool
97
32
}{
98
- {"atlascli" , false },
99
- {"mongocli" , false },
33
+ {
34
+ paths : & homebrew {
35
+ CheckedAt : time .Now (),
36
+ ExecutablePath : "/workplace/mongocli/bin/mongocli" ,
37
+ FormulaPath : "/opt/homebrew/Cellar/mongocli/1.22.0" ,
38
+ },
39
+ isHomebrew : false ,
40
+ },
41
+ {
42
+ paths : & homebrew {
43
+ CheckedAt : time .Now (),
44
+ ExecutablePath : "" ,
45
+ FormulaPath : "/opt/homebrew/Cellar/mongocli/1.22.0" ,
46
+ },
47
+ isHomebrew : false ,
48
+ },
49
+ {
50
+ paths : & homebrew {
51
+ CheckedAt : time .Now (),
52
+ ExecutablePath : "/workplace/mongocli/bin/mongocli" ,
53
+ FormulaPath : "" ,
54
+ },
55
+ isHomebrew : false ,
56
+ },
57
+ {
58
+ paths : & homebrew {
59
+ CheckedAt : time .Now (),
60
+ ExecutablePath : "/workplace/mongocli/bin/mongocli" ,
61
+ FormulaPath : "." ,
62
+ },
63
+ isHomebrew : false ,
64
+ },
65
+ {
66
+ paths : & homebrew {
67
+ CheckedAt : time .Now (),
68
+ ExecutablePath : "/opt/homebrew/Cellar/mongocli/1.22.0/bin" ,
69
+ FormulaPath : "/opt/homebrew/Cellar/mongocli/1.22.0" ,
70
+ },
71
+ isHomebrew : true ,
72
+ },
100
73
}
101
74
102
75
for _ , tt := range tests {
103
- t .Run (fmt .Sprintf ("%v_ishomebrew_%v" , tt .tool , tt .isHb ), func (t * testing.T ) {
104
- ctrl := gomock .NewController (t )
105
- mockStore := mocks .NewMockPathStore (ctrl )
106
- defer ctrl .Finish ()
76
+ t .Run (fmt .Sprintf ("path:%v/formula:%v" , tt .paths .ExecutablePath , tt .paths .FormulaPath ), func (t * testing.T ) {
77
+ appFS := afero .NewMemMapFs ()
78
+ c , err := NewChecker (appFS )
79
+ if err != nil {
80
+ t .Errorf ("NewChecker() unexpected error: %v" , err )
81
+ }
107
82
108
- mockStore .EXPECT ().LoadBrewPath ().Return ("" , "" , nil )
109
- mockStore .EXPECT ().SaveBrewPath (gomock .Any (), gomock .Any ()).Return (nil )
83
+ err = c .save (tt .paths )
84
+ if err != nil {
85
+ t .Errorf ("save() unexpected error: %v" , err )
86
+ }
110
87
111
- result := IsHomebrew (mockStore )
112
- if result != tt .isHb {
113
- t .Errorf ("got = %v, want %v" , result , tt .isHb )
88
+ result := c . IsHomebrew ()
89
+ if result != tt .isHomebrew {
90
+ t .Errorf ("got = %v, want %v" , result , tt .isHomebrew )
114
91
}
115
92
})
116
93
}
0 commit comments