Skip to content

Commit 07a083b

Browse files
fixed tests
1 parent 5ab3246 commit 07a083b

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

codacy-client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
)
1212

1313
const timeout = 10 * time.Second
14-
const CodacyApiBase = "https://app.codacy.com"
14+
15+
var CodacyApiBase = "https://app.codacy.com"
1516

1617
func getRequest(url string, apiToken string) ([]byte, error) {
1718
client := &http.Client{

tools/getTools_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ package tools
33
import (
44
"testing"
55

6+
"codacy/cli-v2/domain"
7+
68
"github.com/stretchr/testify/assert"
79
)
810

911
func TestFilterToolsByConfigUsage(t *testing.T) {
1012
tests := []struct {
1113
name string
12-
inputTools []Tool
14+
inputTools []domain.Tool
1315
expectedCount int
1416
expectedTools []string
1517
}{
1618
{
1719
name: "tools with UsesConfigurationFile=true should be filtered out",
18-
inputTools: []Tool{
20+
inputTools: []domain.Tool{
1921
{
2022
Uuid: "eslint-uuid",
2123
Name: "eslint",
@@ -61,7 +63,7 @@ func TestFilterToolsByConfigUsage(t *testing.T) {
6163
},
6264
{
6365
name: "all tools using config should be filtered out",
64-
inputTools: []Tool{
66+
inputTools: []domain.Tool{
6567
{
6668
Uuid: "eslint-uuid",
6769
Name: "eslint",
@@ -94,7 +96,7 @@ func TestFilterToolsByConfigUsage(t *testing.T) {
9496
},
9597
{
9698
name: "no tools using config should all pass through",
97-
inputTools: []Tool{
99+
inputTools: []domain.Tool{
98100
{
99101
Uuid: "eslint-uuid",
100102
Name: "eslint",

tools/language_config_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14+
codacyclient "codacy/cli-v2/codacy-client"
1415
"codacy/cli-v2/domain"
1516

1617
"github.com/stretchr/testify/assert"
@@ -274,9 +275,9 @@ func TestCreateLanguagesConfigFile_ExtensionsFromRepository(t *testing.T) {
274275
defer server.Close()
275276

276277
// Patch CodacyApiBase to use the test server
277-
oldBase := CodacyApiBase
278-
CodacyApiBase = server.URL
279-
defer func() { CodacyApiBase = oldBase }()
278+
oldBase := codacyclient.CodacyApiBase
279+
codacyclient.CodacyApiBase = server.URL
280+
defer func() { codacyclient.CodacyApiBase = oldBase }()
280281

281282
apiTools := []domain.Tool{
282283
{Uuid: "eslint-uuid"},
@@ -289,14 +290,20 @@ func TestCreateLanguagesConfigFile_ExtensionsFromRepository(t *testing.T) {
289290
"pmd-uuid": "pmd",
290291
}
291292

292-
err := CreateLanguagesConfigFile(apiTools, tempDir, toolIDMap, "test-token", "gh", "org", "repo")
293+
initFlags := domain.InitFlags{
294+
ApiToken: "test-token",
295+
Provider: "gh",
296+
Organization: "org",
297+
Repository: "repo",
298+
}
299+
err := CreateLanguagesConfigFile(apiTools, tempDir, toolIDMap, initFlags)
293300
assert.NoError(t, err)
294301

295302
// Read and unmarshal the generated YAML
296303
data, err := os.ReadFile(tempDir + "/languages-config.yaml")
297304
assert.NoError(t, err)
298305

299-
var config LanguagesConfig
306+
var config domain.LanguagesConfig
300307
err = yaml.Unmarshal(data, &config)
301308
assert.NoError(t, err)
302309

@@ -309,11 +316,11 @@ func TestCreateLanguagesConfigFile_ExtensionsFromRepository(t *testing.T) {
309316
assert.ElementsMatch(t, []string{".cls", ".app", ".trigger", ".scala", ".rb", ".gemspec", ".js", ".jsx", ".vue"}, pmd.Extensions)
310317
}
311318

312-
func findTool(tools []ToolLanguageInfo, name string) ToolLanguageInfo {
319+
func findTool(tools []domain.ToolLanguageInfo, name string) domain.ToolLanguageInfo {
313320
for _, t := range tools {
314321
if t.Name == name {
315322
return t
316323
}
317324
}
318-
return ToolLanguageInfo{}
325+
return domain.ToolLanguageInfo{}
319326
}

0 commit comments

Comments
 (0)