@@ -2,7 +2,6 @@ package agent
22
33import (
44 "testing"
5- "time"
65
76 "yc-agent/internal/config"
87 "yc-agent/internal/logger"
@@ -11,11 +10,7 @@ import (
1110)
1211
1312func TestRun (t * testing.T ) {
14- // TODO: Revisit this test - currently failing in CI
15- // The test subcase "should_handle_invalid_glob_pattern" is failing.
16- // May be related to environment differences or test expectations needing adjustment.
17- t .Skip ("Skipping until invalid glob pattern handling can be reviewed" )
18-
13+ // Tests basic mode validation error cases that return immediately
1914 // Save original config and restore after tests
2015 originalConfig := config .GlobalConfig
2116 defer func () {
@@ -63,142 +58,23 @@ func TestRun(t *testing.T) {
6358 err := Run ()
6459 assert .Equal (t , ErrConflictingMode , err )
6560 })
66- }
67-
68- func TestModeValidation (t * testing.T ) {
69- // TODO: Revisit this test - currently failing in CI
70- // The test validates mode combinations (ondemand, m3, api) but has timing/blocking issues
71- // with goroutines and channels. Needs investigation of async behavior in CI environment.
72- // Related tests: m3 only, api only, ondemand_and_m3_conflict, m3_and_api_together, ondemand_and_api_together
73- t .Skip ("Skipping until mode validation async behavior can be fixed" )
74-
75- // Save original config and restore after tests
76- originalConfig := config .GlobalConfig
77- defer func () {
78- config .GlobalConfig = originalConfig
79- }()
8061
81- // Initialize logger for tests
82- logger .Init ("" , 0 , 0 , "info" )
62+ t .Run ("all three modes conflict" , func (t * testing.T ) {
63+ config .GlobalConfig = config.Config {
64+ Options : config.Options {
65+ Pid : "12345" , // OnDemand mode enabled
66+ M3 : true , // M3 mode enabled
67+ Port : 8080 , // API mode enabled
68+ },
69+ }
8370
84- // Create temp directory for test artifacts
85- tempDir := t .TempDir ()
86-
87- tests := []struct {
88- name string
89- pid string
90- m3 bool
91- port int
92- expectedErr error
93- description string
94- }{
95- {
96- name : "no mode specified" ,
97- pid : "" ,
98- m3 : false ,
99- port : 0 ,
100- expectedErr : ErrNothingCanBeDone ,
101- description : "neither ondemand, m3, nor api mode is enabled" ,
102- },
103- {
104- name : "ondemand only" ,
105- pid : "12345" ,
106- m3 : false ,
107- port : 0 ,
108- expectedErr : nil ,
109- description : "valid ondemand mode" ,
110- },
111- {
112- name : "m3 only" ,
113- pid : "" ,
114- m3 : true ,
115- port : 0 ,
116- expectedErr : nil ,
117- description : "valid m3 mode" ,
118- },
119- {
120- name : "api only" ,
121- pid : "" ,
122- m3 : false ,
123- port : 8080 ,
124- expectedErr : nil ,
125- description : "valid api mode" ,
126- },
127- {
128- name : "ondemand and m3 conflict" ,
129- pid : "12345" ,
130- m3 : true ,
131- port : 0 ,
132- expectedErr : ErrConflictingMode ,
133- description : "ondemand and m3 cannot run together" ,
134- },
135- {
136- name : "m3 and api together" ,
137- pid : "" ,
138- m3 : true ,
139- port : 8080 ,
140- expectedErr : nil ,
141- description : "m3 and api can run together" ,
142- },
143- {
144- name : "ondemand and api together" ,
145- pid : "12345" ,
146- m3 : false ,
147- port : 8080 ,
148- expectedErr : nil ,
149- description : "ondemand and api can run together (backward compatibility)" ,
150- },
151- {
152- name : "all three modes" ,
153- pid : "12345" ,
154- m3 : true ,
155- port : 8080 ,
156- expectedErr : ErrConflictingMode ,
157- description : "ondemand conflicts with m3 even with api mode" ,
158- },
159- }
160-
161- for _ , tt := range tests {
162- t .Run (tt .name , func (t * testing.T ) {
163- config .GlobalConfig = config.Config {
164- Options : config.Options {
165- Pid : tt .pid ,
166- M3 : tt .m3 ,
167- Port : tt .port ,
168- Address : "localhost" ,
169- OnlyCapture : true , // Required to avoid upload logic in ondemand mode
170- JavaHomePath : "/usr/lib/jvm/java-11" ,
171- StoragePath : tempDir , // Use temp directory for test artifacts
172- },
173- }
174-
175- // Create a channel to catch the error or timeout
176- errChan := make (chan error , 1 )
177-
178- go func () {
179- err := Run ()
180- errChan <- err
181- }()
182-
183- // Wait for error or timeout
184- select {
185- case err := <- errChan :
186- assert .Equal (t , tt .expectedErr , err , tt .description )
187- case <- time .After (100 * time .Millisecond ):
188- // If we timeout, it means Run() is blocking (which is expected for m3/api modes)
189- assert .Nil (t , tt .expectedErr , "%s: expected error %v, but Run() is blocking" , tt .description , tt .expectedErr )
190- // This is expected behavior for valid m3/api modes - they block indefinitely
191- }
192- })
193- }
71+ err := Run ()
72+ assert .Equal (t , ErrConflictingMode , err )
73+ })
19474}
19575
19676func TestResolvePidsFromToken (t * testing.T ) {
197- // TODO: Revisit this test - currently failing in CI
198- // Test attempts to resolve PIDs from process tokens but may depend on
199- // environment-specific processes that don't exist in CI. Needs mocking.
200- t .Skip ("Skipping until PID resolution can be properly mocked" )
201-
77+ // Tests PID resolution from process tokens - uses nonexistent token to avoid env dependency
20278 // Save original config and restore after tests
20379 originalConfig := config .GlobalConfig
20480 defer func () {
@@ -214,18 +90,3 @@ func TestResolvePidsFromToken(t *testing.T) {
21490 assert .Empty (t , pids , "expected empty pids slice for nonexistent token" )
21591 })
21692}
217-
218- func TestModeLogic (t * testing.T ) {
219- // TODO: Revisit this test - currently failing in CI
220- // Empty test that may have been a placeholder. Needs implementation or removal.
221- t .Skip ("Skipping empty test - needs implementation" )
222-
223- // Save original config and restore after tests
224- originalConfig := config .GlobalConfig
225- defer func () {
226- config .GlobalConfig = originalConfig
227- }()
228-
229- // Initialize logger for tests
230- logger .Init ("" , 0 , 0 , "info" )
231- }
0 commit comments