Skip to content

Commit 789b03b

Browse files
satyakota04Harness
authored andcommitted
feat:[CI-18864]:fixed the lint issues (#451)
* 62565d fixed the lint issues
1 parent fc03998 commit 789b03b

File tree

3 files changed

+110
-151
lines changed

3 files changed

+110
-151
lines changed

pipeline/runtime/runtestsV2.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/harness/lite-engine/common"
2121
"github.com/harness/lite-engine/internal/filesystem"
2222
"github.com/harness/lite-engine/pipeline"
23-
tiCfg "github.com/harness/lite-engine/ti/config"
2423
"github.com/harness/lite-engine/ti/callgraph"
24+
tiCfg "github.com/harness/lite-engine/ti/config"
2525
"github.com/harness/lite-engine/ti/instrumentation"
2626
tiCommon "github.com/harness/lite-engine/ti/instrumentation/common"
2727
"github.com/harness/lite-engine/ti/instrumentation/csharp"
@@ -1220,8 +1220,6 @@ func collectTestReportsAndCg(
12201220
log.Infoln(fmt.Sprintf("Successfully collected test reports in %s time", time.Since(reportStart)))
12211221
}
12221222

1223-
1224-
// Assign detected languages from callgraph to testMetadata
12251223
if len(callgraph.DetectedLanguages) > 0 {
12261224
telemetryData.TestIntelligenceMetaData.Language = callgraph.DetectedLanguages
12271225
}

ti/callgraph/upload.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func parseCallgraphFiles(dataDir string, log *logrus.Logger) (*Callgraph, error)
136136
return cg, nil
137137
}
138138

139-
// encodeCg reads all files of specified format from datadir folder and returns byte array of avro encoded format
139+
//nolint:funlen
140140
func encodeCg(dataDir string, log *logrus.Logger, tests []*tiClientTypes.TestCase, version string, rerunFailedTests bool) (data []byte, isEmpty, allMatched bool, err error) {
141141
var parser Parser
142142
var cgIsEmpty bool
@@ -158,8 +158,6 @@ func encodeCg(dataDir string, log *logrus.Logger, tests []*tiClientTypes.TestCas
158158
}
159159

160160
log.Infof("Callgraph parsing completed. Total nodes: %d", len(cg.Nodes))
161-
162-
// Initialize language detection map
163161
languageSet := make(map[string]bool)
164162

165163
// Handle failed test matching and language detection in a single loop
@@ -171,7 +169,6 @@ func encodeCg(dataDir string, log *logrus.Logger, tests []*tiClientTypes.TestCas
171169
if cg.Nodes[i].Type != nodeTypeTest {
172170
continue
173171
}
174-
// Detect language from file extension
175172
if cg.Nodes[i].File != "" {
176173
ext := filepath.Ext(cg.Nodes[i].File)
177174
if ext != "" {
@@ -192,7 +189,6 @@ func encodeCg(dataDir string, log *logrus.Logger, tests []*tiClientTypes.TestCas
192189
}
193190
}
194191
} else {
195-
// When not rerunning failed tests, only detect languages
196192
for i := range cg.Nodes {
197193
if cg.Nodes[i].Type == nodeTypeTest && cg.Nodes[i].File != "" {
198194
ext := filepath.Ext(cg.Nodes[i].File)
@@ -202,8 +198,6 @@ func encodeCg(dataDir string, log *logrus.Logger, tests []*tiClientTypes.TestCas
202198
}
203199
}
204200
}
205-
206-
// Convert language set to slice and store in global variable
207201
if len(languageSet) > 0 {
208202
languages := make([]string, 0, len(languageSet))
209203
for lang := range languageSet {

ti/callgraph/upload_test.go

Lines changed: 108 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -73,162 +73,129 @@ func TestCallGraphParser_EncodeCg(t *testing.T) {
7373
assert.NotEmpty(t, cg.TestRelations)
7474
}
7575

76-
func TestLanguageDetection(t *testing.T) {
77-
log := logrus.New()
78-
79-
// Helper function to create test callgraph with file extensions
80-
createTestCg := func(fileExt string) *Callgraph {
81-
return &Callgraph{
82-
Nodes: []Node{
83-
{
84-
ID: 1,
85-
ClassID: 100,
86-
Package: "io.harness.test",
87-
Class: "TestClass",
88-
Method: "testMethod",
89-
Params: "()",
90-
Type: "test",
91-
File: "io/harness/test/TestClass" + fileExt,
92-
},
93-
{
94-
ID: 2,
95-
ClassID: 200,
96-
Package: "io.harness.source",
97-
Class: "SourceClass",
98-
Method: "sourceMethod",
99-
Params: "()",
100-
Type: "source",
101-
},
76+
// Helper function to create test callgraph with file extensions
77+
func createTestCg(fileExt string) *Callgraph {
78+
return &Callgraph{
79+
Nodes: []Node{
80+
{
81+
ID: 1,
82+
ClassID: 100,
83+
Package: "io.harness.test",
84+
Class: "TestClass",
85+
Method: "testMethod",
86+
Params: "()",
87+
Type: "test",
88+
File: "io/harness/test/TestClass" + fileExt,
10289
},
103-
TestRelations: []Relation{
104-
{Source: 2, Tests: []int{1}},
90+
{
91+
ID: 2,
92+
ClassID: 200,
93+
Package: "io.harness.source",
94+
Class: "SourceClass",
95+
Method: "sourceMethod",
96+
Params: "()",
97+
Type: "source",
10598
},
106-
}
99+
},
100+
TestRelations: []Relation{
101+
{Source: 2, Tests: []int{1}},
102+
},
107103
}
104+
}
108105

109-
// Test 1: Language detection with Java files (rerunFailedTests = false)
110-
t.Run("Language detection without rerun failed tests", func(t *testing.T) {
111-
DetectedLanguages = []string{}
112-
cg := createTestCg(".java")
113-
114-
// Simulate the language detection logic from encodeCg
115-
languageSet := make(map[string]bool)
116-
for i := range cg.Nodes {
117-
if cg.Nodes[i].Type == nodeTypeTest && cg.Nodes[i].File != "" {
118-
ext := ".java" // filepath.Ext would return this
119-
if ext != "" {
120-
languageSet[ext] = true
121-
}
106+
// Helper function to simulate language detection logic
107+
func simulateLanguageDetection(cg *Callgraph, ext string) {
108+
languageSet := make(map[string]bool)
109+
for i := range cg.Nodes {
110+
if cg.Nodes[i].Type == nodeTypeTest && cg.Nodes[i].File != "" {
111+
if ext != "" {
112+
languageSet[ext] = true
122113
}
123114
}
124-
if len(languageSet) > 0 {
125-
languages := make([]string, 0, len(languageSet))
126-
for lang := range languageSet {
127-
languages = append(languages, lang)
128-
}
129-
DetectedLanguages = languages
115+
}
116+
if len(languageSet) > 0 {
117+
languages := make([]string, 0, len(languageSet))
118+
for lang := range languageSet {
119+
languages = append(languages, lang)
130120
}
121+
DetectedLanguages = languages
122+
}
123+
}
131124

132-
assert.NotEmpty(t, DetectedLanguages, "Languages should be detected even when rerunFailedTests is false")
133-
assert.Contains(t, DetectedLanguages, ".java")
134-
log.Infof("Detected languages (rerunFailedTests=false): %v", DetectedLanguages)
135-
})
136-
137-
// Test 2: Language detection with Python files (rerunFailedTests = true)
138-
t.Run("Language detection with rerun failed tests", func(t *testing.T) {
139-
DetectedLanguages = []string{}
140-
cg := createTestCg(".py")
141-
142-
// Simulate the language detection logic with rerunFailedTests = true
143-
languageSet := make(map[string]bool)
144-
for i := range cg.Nodes {
145-
cg.Nodes[i].HasFailed = false
146-
if cg.Nodes[i].Type != nodeTypeTest {
147-
continue
148-
}
149-
if cg.Nodes[i].File != "" {
150-
ext := ".py"
151-
if ext != "" {
152-
languageSet[ext] = true
153-
}
154-
}
155-
}
156-
if len(languageSet) > 0 {
157-
languages := make([]string, 0, len(languageSet))
158-
for lang := range languageSet {
159-
languages = append(languages, lang)
160-
}
161-
DetectedLanguages = languages
162-
}
125+
func TestLanguageDetectionWithoutRerun(t *testing.T) {
126+
log := logrus.New()
127+
DetectedLanguages = []string{}
128+
cg := createTestCg(".java")
163129

164-
assert.NotEmpty(t, DetectedLanguages, "Languages should be detected when rerunFailedTests is true")
165-
assert.Contains(t, DetectedLanguages, ".py")
166-
log.Infof("Detected languages (rerunFailedTests=true): %v", DetectedLanguages)
167-
})
168-
169-
// Test 3: No languages detected for empty callgraph
170-
t.Run("No languages for empty callgraph", func(t *testing.T) {
171-
DetectedLanguages = []string{}
172-
cg := &Callgraph{
173-
Nodes: []Node{},
174-
TestRelations: []Relation{},
175-
}
130+
simulateLanguageDetection(cg, ".java")
176131

177-
languageSet := make(map[string]bool)
178-
for i := range cg.Nodes {
179-
if cg.Nodes[i].Type == nodeTypeTest && cg.Nodes[i].File != "" {
180-
ext := ""
181-
if ext != "" {
182-
languageSet[ext] = true
183-
}
184-
}
132+
assert.NotEmpty(t, DetectedLanguages, "Languages should be detected even when rerunFailedTests is false")
133+
assert.Contains(t, DetectedLanguages, ".java")
134+
log.Infof("Detected languages (rerunFailedTests=false): %v", DetectedLanguages)
135+
}
136+
137+
func TestLanguageDetectionWithRerun(t *testing.T) {
138+
log := logrus.New()
139+
DetectedLanguages = []string{}
140+
cg := createTestCg(".py")
141+
142+
// Simulate the language detection logic with rerunFailedTests = true
143+
languageSet := make(map[string]bool)
144+
for i := range cg.Nodes {
145+
cg.Nodes[i].HasFailed = false
146+
if cg.Nodes[i].Type != nodeTypeTest {
147+
continue
185148
}
186-
if len(languageSet) > 0 {
187-
languages := make([]string, 0, len(languageSet))
188-
for lang := range languageSet {
189-
languages = append(languages, lang)
149+
if cg.Nodes[i].File != "" {
150+
ext := ".py"
151+
if ext != "" {
152+
languageSet[ext] = true
190153
}
191-
DetectedLanguages = languages
192154
}
155+
}
156+
if len(languageSet) > 0 {
157+
languages := make([]string, 0, len(languageSet))
158+
for lang := range languageSet {
159+
languages = append(languages, lang)
160+
}
161+
DetectedLanguages = languages
162+
}
163+
164+
assert.NotEmpty(t, DetectedLanguages, "Languages should be detected when rerunFailedTests is true")
165+
assert.Contains(t, DetectedLanguages, ".py")
166+
log.Infof("Detected languages (rerunFailedTests=true): %v", DetectedLanguages)
167+
}
168+
169+
func TestLanguageDetectionEmptyCallgraph(t *testing.T) {
170+
DetectedLanguages = []string{}
171+
cg := &Callgraph{
172+
Nodes: []Node{},
173+
TestRelations: []Relation{},
174+
}
175+
176+
simulateLanguageDetection(cg, "")
193177

194-
assert.Empty(t, DetectedLanguages, "No languages should be detected for empty callgraph")
195-
})
196-
197-
// Test 4: No languages detected when nodes have no file field
198-
t.Run("No languages when nodes have no file field", func(t *testing.T) {
199-
DetectedLanguages = []string{}
200-
cg := &Callgraph{
201-
Nodes: []Node{
202-
{
203-
ID: 1,
204-
ClassID: 100,
205-
Package: "io.harness.test",
206-
Class: "TestClass",
207-
Method: "testMethod",
208-
Type: "test",
209-
File: "", // Empty file field
210-
},
178+
assert.Empty(t, DetectedLanguages, "No languages should be detected for empty callgraph")
179+
}
180+
181+
func TestLanguageDetectionNoFileField(t *testing.T) {
182+
DetectedLanguages = []string{}
183+
cg := &Callgraph{
184+
Nodes: []Node{
185+
{
186+
ID: 1,
187+
ClassID: 100,
188+
Package: "io.harness.test",
189+
Class: "TestClass",
190+
Method: "testMethod",
191+
Type: "test",
192+
File: "",
211193
},
212-
TestRelations: []Relation{},
213-
}
194+
},
195+
TestRelations: []Relation{},
196+
}
214197

215-
languageSet := make(map[string]bool)
216-
for i := range cg.Nodes {
217-
if cg.Nodes[i].Type == nodeTypeTest && cg.Nodes[i].File != "" {
218-
ext := ""
219-
if ext != "" {
220-
languageSet[ext] = true
221-
}
222-
}
223-
}
224-
if len(languageSet) > 0 {
225-
languages := make([]string, 0, len(languageSet))
226-
for lang := range languageSet {
227-
languages = append(languages, lang)
228-
}
229-
DetectedLanguages = languages
230-
}
198+
simulateLanguageDetection(cg, "")
231199

232-
assert.Empty(t, DetectedLanguages, "No languages should be detected when nodes have no file field")
233-
})
200+
assert.Empty(t, DetectedLanguages, "No languages should be detected when nodes have no file field")
234201
}

0 commit comments

Comments
 (0)