@@ -43,11 +43,17 @@ func TestHandlePackageCommand(t *testing.T) {
4343 },
4444 },
4545 {
46- name : "chart path with destination flag" ,
46+ name : "chart path with destination flag - long form " ,
4747 args : func (chartPath , destination string ) []string {
4848 return []string {chartPath , "--destination" , destination }
4949 },
5050 },
51+ {
52+ name : "chart path with destination flag - short form" ,
53+ args : func (chartPath , destination string ) []string {
54+ return []string {chartPath , "-d" , destination }
55+ },
56+ },
5157 }
5258
5359 for _ , tt := range tests {
@@ -69,6 +75,90 @@ func TestHandlePackageCommand(t *testing.T) {
6975 }
7076}
7177
78+ func TestHandlePackageCommand_NoChartDir (t * testing.T ) {
79+ t .Setenv ("JFROG_CLI_HOME_DIR" , t .TempDir ())
80+ tests := []struct {
81+ name string
82+ args func (chartPath , destination string ) []string
83+ }{
84+ {
85+ name : "Destination exists but no Chart.yaml" ,
86+ args : func (chartPath , destination string ) []string {
87+ return []string {chartPath , "-d" , destination }
88+ },
89+ },
90+ {
91+ name : "No chart among paths" ,
92+ args : func (chartPath , _ string ) []string {
93+ return []string {chartPath }
94+ },
95+ },
96+ {
97+ name : "No paths" ,
98+ args : func (_ , _ string ) []string {
99+ return []string {}
100+ },
101+ },
102+ }
103+
104+ for _ , tt := range tests {
105+ t .Run (tt .name , func (t * testing.T ) {
106+ notAChartDir := t .TempDir ()
107+ destination := t .TempDir ()
108+ buildInfo := entities .New ()
109+ err := handlePackageCommand (
110+ buildInfo ,
111+ tt .args (notAChartDir , destination ),
112+ & mockPackageServicesManager {},
113+ "helm-package-test" ,
114+ "1" ,
115+ "" ,
116+ )
117+ require .ErrorIs (t , err , ErrNoChartDirFound , "Expected error when no valid chart directory is specified" )
118+ require .Empty (t , buildInfo .Modules , "Expected no modules in build info when no chart directory is found" )
119+ })
120+ }
121+ }
122+
123+ func TestIsChartDir (t * testing.T ) {
124+ tests := []struct {
125+ name string
126+ dir string
127+ expected bool
128+ }{
129+ {
130+ name : "Chart directory exists and contains Chart.yaml" ,
131+ dir : createHelmChartWithDependencies (t ),
132+ expected : true ,
133+ },
134+ {
135+ name : "Chart directory exists but does not contain Chart.yaml" ,
136+ dir : t .TempDir (),
137+ expected : false ,
138+ },
139+ {
140+ name : "Chart directory does not exist" ,
141+ dir : filepath .Join (t .TempDir (), "nonexistent" ),
142+ expected : false ,
143+ },
144+ {
145+ name : "Chart directory exists but permission denied" ,
146+ dir : func () string {
147+ chartPath := t .TempDir ()
148+ _ = os .Chmod (chartPath , 0o000 ) // Remove all permissions
149+ return chartPath
150+ }(),
151+ expected : false ,
152+ },
153+ }
154+
155+ for _ , tt := range tests {
156+ t .Run (tt .name , func (t * testing.T ) {
157+ require .Equal (t , tt .expected , isChartDir (tt .dir ))
158+ })
159+ }
160+ }
161+
72162func createHelmChartWithDependencies (t * testing.T ) string {
73163 t .Helper ()
74164
@@ -203,4 +293,4 @@ func requireBuildInfoDetails(t *testing.T, buildInfo *entities.BuildInfo) {
203293 }
204294 require .True (t , depIds ["subchart-a:0.1.0" ])
205295 require .True (t , depIds ["subchart-b:0.2.0" ])
206- }
296+ }
0 commit comments