-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
ae5aea2
commit dc5535d
Showing
6 changed files
with
134 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,12 @@ | |
package io.seqera.wave.service.persistence | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import java.time.Duration | ||
import java.time.Instant | ||
|
||
import io.seqera.wave.service.scan.ScanResult | ||
import io.seqera.wave.service.scan.ScanVulnerability | ||
|
||
/** | ||
* | ||
* @author Munish Chouhan <[email protected]> | ||
|
@@ -65,6 +63,7 @@ class WaveScanRecordTest extends Specification { | |
scanResult.containerImage == containerImage | ||
scanResult.isCompleted() | ||
scanResult.isSucceeded() | ||
scanResult.done() | ||
|
||
when: | ||
def scanRecord = new WaveScanRecord(scanId, scanResult) | ||
|
@@ -75,14 +74,4 @@ class WaveScanRecordTest extends Specification { | |
scanRecord.vulnerabilities[0] == scanVulnerability | ||
} | ||
|
||
@Unroll | ||
def 'should validate done' () { | ||
expect: | ||
RECORD.done() == EXPECTED | ||
|
||
where: | ||
EXPECTED| RECORD | ||
false | new WaveScanRecord('123', 'scan-123', 'testcontainerimage', Instant.now()) | ||
true | new WaveScanRecord('123', 'scan-123', 'testcontainerimage', Instant.now(), Duration.ofMinutes(1), 'OK', []) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,6 @@ import java.time.Duration | |
import java.time.Instant | ||
|
||
import io.seqera.wave.core.ContainerPlatform | ||
import io.seqera.wave.service.persistence.WaveScanRecord | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
|
@@ -78,6 +76,7 @@ class ScanResultTest extends Specification { | |
) | ||
then: | ||
result.isCompleted() == EXPECTED | ||
result.done() == EXPECTED | ||
|
||
where: | ||
DURATION | EXPECTED | ||
|
@@ -129,16 +128,16 @@ class ScanResultTest extends Specification { | |
def elapsed = Duration.ofMinutes(1) | ||
def ts = Instant.now().minus(elapsed) | ||
and: | ||
def record = new WaveScanRecord( | ||
id: '12345', | ||
buildId: 'build-12345', | ||
containerImage: 'docker.io/some:image', | ||
startTime: ts, | ||
duration: elapsed, | ||
status: ScanResult.SUCCEEDED, | ||
vulnerabilities: [cve1] ) | ||
def scan = new ScanResult( | ||
'12345', | ||
'build-12345', | ||
'docker.io/some:image', | ||
ts, | ||
elapsed, | ||
ScanResult.SUCCEEDED, | ||
[cve1] ) | ||
when: | ||
def result = ScanResult.success(record, record.vulnerabilities) | ||
def result = scan.success(scan.vulnerabilities) | ||
then: | ||
result.id == '12345' | ||
result.buildId == 'build-12345' | ||
|
@@ -154,16 +153,16 @@ class ScanResultTest extends Specification { | |
def elapsed = Duration.ofMinutes(1) | ||
def ts = Instant.now().minus(elapsed) | ||
and: | ||
def record = new WaveScanRecord( | ||
id: '12345', | ||
buildId: 'build-12345', | ||
containerImage: 'docker.io/some:image', | ||
startTime: ts, | ||
duration: elapsed, | ||
status: ScanResult.FAILED, | ||
vulnerabilities: [] ) | ||
def scan = new ScanResult( | ||
'12345', | ||
'build-12345', | ||
'docker.io/some:image', | ||
ts, | ||
elapsed, | ||
ScanResult.FAILED, | ||
[] ) | ||
when: | ||
def result = ScanResult.failure(record) | ||
def result = scan.failure(1, "Oops something has failed") | ||
then: | ||
result.id == '12345' | ||
result.buildId == 'build-12345' | ||
|
@@ -172,6 +171,8 @@ class ScanResultTest extends Specification { | |
nearly(result.duration, elapsed) | ||
result.status == ScanResult.FAILED | ||
result.vulnerabilities == [] | ||
result.exitCode == 1 | ||
result.logs == "Oops something has failed" | ||
} | ||
|
||
def 'should create failed result from request' () { | ||
|
@@ -198,4 +199,21 @@ class ScanResultTest extends Specification { | |
result.status == ScanResult.FAILED | ||
result.vulnerabilities == [] | ||
} | ||
|
||
def 'should create scan pending' () { | ||
given: | ||
def ts = Instant.now() | ||
|
||
when: | ||
def scan = ScanResult.pending('result-123', 'build-345', 'docker.io/foo/bar') | ||
then: | ||
scan.id == 'result-123' | ||
scan.buildId == 'build-345' | ||
scan.containerImage == 'docker.io/foo/bar' | ||
scan.startTime >= ts | ||
scan.status == ScanResult.PENDING | ||
scan.vulnerabilities == [] | ||
scan.exitCode == null | ||
scan.logs == null | ||
} | ||
} |