@@ -152,3 +152,114 @@ func TestPredicateWithInvalidValues(t *testing.T) {
152152 _ = unmarshall (t , responseKics , & kicsPredicate , "Reading predicate should pass" )
153153 assert .Assert (t , kicsPredicate .TotalCount == 0 , "Predicate with invalid values should have 0 as the result." )
154154}
155+
156+
157+
158+ func TestSastUpdateAndGetPredicateWithCustomStateID (t * testing.T ) {
159+ t .Skip ("Skipping TestSastUpdateAndGetPredicateWithCustomStateID for now" )
160+
161+ scanID , projectID := getRootScan (t )
162+ _ = executeCmdNilAssertion (
163+ t , "Results show generating JSON report with options should pass" ,
164+ "results" , "show" ,
165+ flag (params .ScanIDFlag ), scanID , flag (params .TargetFormatFlag ), printer .FormatJSON ,
166+ flag (params .TargetPathFlag ), resultsDirectory ,
167+ flag (params .TargetFlag ), fileName ,
168+ )
169+
170+ defer func () {
171+ _ = os .RemoveAll (fmt .Sprintf (resultsDirectory ))
172+ }()
173+
174+ result := wrappers.ScanResultsCollection {}
175+
176+ _ , err := os .Stat (fmt .Sprintf ("%s%s.%s" , resultsDirectory , fileName , printer .FormatJSON ))
177+ assert .NilError (t , err , "Report file should exist for extension " + printer .FormatJSON )
178+
179+ file , err := os .ReadFile (fmt .Sprintf ("%s%s.%s" , resultsDirectory , fileName , printer .FormatJSON ))
180+ assert .NilError (t , err , "error reading file" )
181+
182+ err = json .Unmarshal (file , & result )
183+ assert .NilError (t , err , "error unmarshalling file" )
184+
185+ index := 0
186+ for i := range result .Results {
187+ if strings .EqualFold (result .Results [i ].Type , params .SastType ) {
188+ index = i
189+ break
190+ }
191+ }
192+
193+ similarityID := result .Results [index ].SimilarityID
194+ scanType := result .Results [index ].Type
195+
196+ fmt .Println ("Step 1: Testing the command 'triage show' to get the initial predicate state." )
197+ outputBufferInitial := executeCmdNilAssertion (
198+ t , "Initial predicates should be fetched." , "triage" , "show" ,
199+ flag (params .FormatFlag ), printer .FormatJSON ,
200+ flag (params .ProjectIDFlag ), projectID ,
201+ flag (params .SimilarityIDFlag ), similarityID ,
202+ flag (params .ScanTypeFlag ), scanType ,
203+ )
204+
205+ predicateResultInitial := []wrappers.Predicate {}
206+ _ = unmarshall (t , outputBufferInitial , & predicateResultInitial , "Reading initial results should pass" )
207+
208+ var initialState string
209+ foundInitial := false
210+ for _ , predicate := range predicateResultInitial {
211+ if predicate .StateID == 324 {
212+ initialState = predicate .State
213+ foundInitial = true
214+ break
215+ }
216+ }
217+ if ! foundInitial {
218+ initialState = "Not set"
219+ }
220+ fmt .Printf ("Initial state for state-id 324: %s\n " , initialState )
221+
222+ fmt .Println ("Step 2: Testing the command 'triage update' with custom state-id to update the predicate." )
223+ severity := "HIGH"
224+ comment := "Testing CLI Command with custom state-id."
225+
226+ args := []string {
227+ "triage" , "update" ,
228+ flag (params .ProjectIDFlag ), projectID ,
229+ flag (params .SimilarityIDFlag ), similarityID ,
230+ flag (params .CustomStateIDFlag ), "324" ,
231+ flag (params .StateFlag ), "triageTest" ,
232+ flag (params .SeverityFlag ), severity ,
233+ flag (params .CommentFlag ), comment ,
234+ flag (params .ScanTypeFlag ), scanType ,
235+ }
236+
237+ err , outputBufferUpdate := executeCommand (t , args ... )
238+ _ , readingError := io .ReadAll (outputBufferUpdate )
239+ assert .NilError (t , readingError , "Reading update result should pass" )
240+ assert .NilError (t , err , "Updating the predicate with custom state-id should pass." )
241+
242+ fmt .Println ("Step 3: Testing the command 'triage show' to verify the updated predicate." )
243+ outputBufferFinal := executeCmdNilAssertion (
244+ t , "Updated predicates should be fetched." , "triage" , "show" ,
245+ flag (params .FormatFlag ), printer .FormatJSON ,
246+ flag (params .ProjectIDFlag ), projectID ,
247+ flag (params .SimilarityIDFlag ), similarityID ,
248+ flag (params .ScanTypeFlag ), scanType ,
249+ )
250+
251+ predicateResultFinal := []wrappers.Predicate {}
252+ _ = unmarshall (t , outputBufferFinal , & predicateResultFinal , "Reading final results should pass" )
253+
254+ assert .Assert (t , len (predicateResultFinal ) >= 1 , "Should have at least 1 predicate as the result after update." )
255+ foundFinal := false
256+ for _ , predicate := range predicateResultFinal {
257+ if predicate .StateID == 324 {
258+ assert .Equal (t , predicate .State , "triageTest" , "The state name for state-id 324 should be updated to triageTest" )
259+ assert .Assert (t , predicate .State != initialState , "The state name for state-id 324 should have changed from initial state %s" , initialState )
260+ foundFinal = true
261+ break
262+ }
263+ }
264+ assert .Assert (t , foundFinal , "Predicate with state-id 324 should be found in the results after update" )
265+ }
0 commit comments