@@ -8,10 +8,15 @@ use std::{
88 fmt:: { self , Display , Formatter } ,
99 panic:: Location ,
1010 path:: PathBuf ,
11+ sync:: { Arc , Mutex } ,
1112} ;
1213
13- use crate :: storage:: { ScanID , inmemory:: InMemoryStorage } ;
14- use crate :: { nasl:: prelude:: * , scanner:: preferences:: preference:: ScanPrefs } ;
14+ use crate :: { nasl:: prelude:: * , notus:: Notus , scanner:: preferences:: preference:: ScanPrefs } ;
15+ use crate :: {
16+ nasl:: utils:: scan_ctx:: NotusCtx ,
17+ notus:: HashsumProductLoader ,
18+ storage:: { ScanID , inmemory:: InMemoryStorage } ,
19+ } ;
1520use futures:: { Stream , StreamExt } ;
1621
1722use super :: {
@@ -129,6 +134,7 @@ pub struct TestBuilder<S: ContextStorage> {
129134 storage : S ,
130135 executor : Executor ,
131136 version : NaslVersion ,
137+ notus : Option < Arc < Mutex < Notus < HashsumProductLoader > > > > ,
132138}
133139
134140pub type DefaultTestBuilder = TestBuilder < InMemoryStorage > ;
@@ -147,6 +153,7 @@ impl Default for TestBuilder<InMemoryStorage> {
147153 storage : InMemoryStorage :: default ( ) ,
148154 executor : nasl_std_functions ( ) ,
149155 version : NaslVersion :: default ( ) ,
156+ notus : None ,
150157 }
151158 }
152159}
@@ -172,6 +179,7 @@ where
172179 storage,
173180 executor : nasl_std_functions ( ) ,
174181 version : NaslVersion :: default ( ) ,
182+ notus : None ,
175183 }
176184 }
177185}
@@ -194,11 +202,10 @@ impl TestBuilder<InMemoryStorage> {
194202 storage : InMemoryStorage :: default ( ) ,
195203 executor : nasl_std_functions ( ) ,
196204 version : NaslVersion :: default ( ) ,
205+ notus : None ,
197206 }
198207 }
199- }
200208
201- impl TestBuilder < InMemoryStorage > {
202209 /// Construct a `TestBuilder`, immediately run the
203210 /// given code on it and return it.
204211 pub fn from_code ( code : impl AsRef < str > ) -> Self {
@@ -212,6 +219,23 @@ impl TestBuilder<InMemoryStorage> {
212219 t. run_all ( code. as_ref ( ) ) ;
213220 t
214221 }
222+
223+ pub fn from_notus ( notus : Arc < Mutex < Notus < HashsumProductLoader > > > ) -> Self {
224+ Self {
225+ lines : vec ! [ ] ,
226+ results : vec ! [ ] ,
227+ scan_id : Default :: default ( ) ,
228+ filename : Default :: default ( ) ,
229+ target : Default :: default ( ) ,
230+ variables : vec ! [ ] ,
231+ should_verify : true ,
232+ loader : Loader :: test_empty ( ) ,
233+ storage : InMemoryStorage :: default ( ) ,
234+ executor : nasl_std_functions ( ) ,
235+ version : NaslVersion :: default ( ) ,
236+ notus : Some ( notus) ,
237+ }
238+ }
215239}
216240
217241impl < S > TestBuilder < S >
@@ -355,7 +379,7 @@ where
355379 filename : self . filename . clone ( ) ,
356380 scan_preferences : ScanPrefs :: new ( ) ,
357381 alive_test_methods : Vec :: default ( ) ,
358- notus : None ,
382+ notus : self . notus . as_ref ( ) . map ( |x| NotusCtx :: Direct ( x . clone ( ) ) ) ,
359383 }
360384 . build ( )
361385 }
0 commit comments