@@ -2,7 +2,6 @@ package cmd
22
33import (
44 "codacy/cli-v2/cmd/configsetup"
5- "codacy/cli-v2/config"
65 "codacy/cli-v2/constants"
76 "codacy/cli-v2/domain"
87 "os"
@@ -182,77 +181,3 @@ func TestCleanConfigDirectory(t *testing.T) {
182181 assert .NoError (t , err )
183182 assert .Equal (t , 0 , len (files ), "Expected 0 files after cleaning, got %d" , len (files ))
184183}
185-
186- func TestInitCommand_NoToken (t * testing.T ) {
187- tempDir := t .TempDir ()
188- originalWD , err := os .Getwd ()
189- assert .NoError (t , err , "Failed to get current working directory" )
190- defer os .Chdir (originalWD )
191-
192- // Use the real plugins/tools/semgrep/rules.yaml file
193- rulesPath := filepath .Join (".." , "plugins" , "tools" , "semgrep" , "rules.yaml" )
194- if _ , err := os .Stat (rulesPath ); os .IsNotExist (err ) {
195- t .Skipf ("plugins/tools/semgrep/rules.yaml not found at %s; skipping test" , rulesPath )
196- }
197-
198- // Change to the temp directory to simulate a new project
199- err = os .Chdir (tempDir )
200- assert .NoError (t , err , "Failed to change working directory to tempDir" )
201-
202- // Simulate running init with no token
203- currentInitFlags := domain.InitFlags {
204- ApiToken : "" ,
205- Provider : "" ,
206- Organization : "" ,
207- Repository : "" ,
208- }
209-
210- // Call the Run logic from initCmd
211- if err := config .Config .CreateLocalCodacyDir (); err != nil {
212- t .Fatalf ("Failed to create local codacy directory: %v" , err )
213- }
214-
215- toolsConfigDir := config .Config .ToolsConfigDirectory ()
216- if err := os .MkdirAll (toolsConfigDir , constants .DefaultDirPerms ); err != nil {
217- t .Fatalf ("Failed to create tools-configs directory: %v" , err )
218- }
219-
220- cliLocalMode := len (currentInitFlags .ApiToken ) == 0
221- if cliLocalMode {
222- noTools := []domain.Tool {}
223- err := configsetup .CreateConfigurationFiles (noTools , cliLocalMode )
224- assert .NoError (t , err , "CreateConfigurationFiles should not return an error" )
225- if err := configsetup .BuildDefaultConfigurationFiles (toolsConfigDir , currentInitFlags ); err != nil {
226- t .Fatalf ("Failed to build default configuration files: %v" , err )
227- }
228- if err := configsetup .CreateLanguagesConfigFileLocal (toolsConfigDir ); err != nil {
229- t .Fatalf ("Failed to create languages config file: %v" , err )
230- }
231- }
232-
233- // Assert that the expected config files are created
234- codacyDir := config .Config .LocalCodacyDirectory ()
235- expectedFiles := []string {
236- filepath .Join ("tools-configs" , "eslint.config.mjs" ),
237- filepath .Join ("tools-configs" , "trivy.yaml" ),
238- filepath .Join ("tools-configs" , "ruleset.xml" ),
239- filepath .Join ("tools-configs" , "pylint.rc" ),
240- filepath .Join ("tools-configs" , "analysis_options.yaml" ),
241- filepath .Join ("tools-configs" , "semgrep.yaml" ),
242- filepath .Join ("tools-configs" , "lizard.yaml" ),
243- "codacy.yaml" ,
244- "cli-config.yaml" ,
245- filepath .Join ("tools-configs" , "languages-config.yaml" ),
246- ".gitignore" ,
247- }
248-
249- for _ , file := range expectedFiles {
250- filePath := filepath .Join (codacyDir , file )
251- if file == ".gitignore" {
252- filePath = filepath .Join (config .Config .LocalCodacyDirectory (), file )
253- }
254-
255- _ , err := os .Stat (filePath )
256- assert .NoError (t , err , "Expected config file %s to be created at %s" , file , filePath )
257- }
258- }
0 commit comments