-
Notifications
You must be signed in to change notification settings - Fork 24
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: David Wertenteil <[email protected]>
- Loading branch information
David Wertenteil
committed
Feb 5, 2023
1 parent
753fd76
commit f144cee
Showing
6 changed files
with
355 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package apis | ||
|
||
import "testing" | ||
|
||
func TestIsPassed(t *testing.T) { | ||
s := &StatusInfo{InnerStatus: StatusPassed} | ||
if !s.IsPassed() { | ||
t.Fatalf("Expected status to be passed, got %v", s.InnerStatus) | ||
} | ||
} | ||
|
||
func TestIsFailed(t *testing.T) { | ||
s := &StatusInfo{InnerStatus: StatusFailed} | ||
if !s.IsFailed() { | ||
t.Fatalf("Expected status to be failed, got %v", s.InnerStatus) | ||
} | ||
} | ||
|
||
func TestIsSkipped(t *testing.T) { | ||
s := &StatusInfo{InnerStatus: StatusSkipped} | ||
if !s.IsSkipped() { | ||
t.Fatalf("Expected status to be skipped, got %v", s.InnerStatus) | ||
} | ||
} | ||
|
||
func TestGetSubStatus(t *testing.T) { | ||
s := &StatusInfo{SubStatus: SubStatusException} | ||
if s.GetSubStatus() != SubStatusException { | ||
t.Fatalf("Expected sub-status to be %v, got %v", SubStatusException, s.GetSubStatus()) | ||
} | ||
} | ||
|
||
func TestStatus(t *testing.T) { | ||
s := &StatusInfo{InnerStatus: StatusPassed} | ||
if s.Status() != StatusPassed { | ||
t.Fatalf("Expected status to be %v, got %v", StatusPassed, s.Status()) | ||
} | ||
} | ||
|
||
func TestInfo(t *testing.T) { | ||
info := "Test info" | ||
s := &StatusInfo{InnerInfo: info} | ||
if s.Info() != info { | ||
t.Fatalf("Expected info to be %v, got %v", info, s.Info()) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kubescape/opa-utils/reporthandling/apis" | ||
) | ||
|
||
func TestNewStatus(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
status apis.ScanningStatus | ||
want apis.ScanningStatus | ||
}{ | ||
{ | ||
name: "Test passed status", | ||
status: apis.StatusPassed, | ||
want: apis.StatusPassed, | ||
}, | ||
{ | ||
name: "Test failed status", | ||
status: apis.StatusFailed, | ||
want: apis.StatusFailed, | ||
}, | ||
{ | ||
name: "Test skipped status", | ||
status: apis.StatusSkipped, | ||
want: apis.StatusSkipped, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
s := NewStatus(tt.status) | ||
if got := s.Status(); got != tt.want { | ||
t.Errorf("NewStatus().Status() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNewStatusInfo(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
status apis.ScanningStatus | ||
subStatus apis.ScanningSubStatus | ||
info string | ||
wantStatus apis.ScanningStatus | ||
wantSubStatus apis.ScanningSubStatus | ||
wantInfo string | ||
}{ | ||
{ | ||
name: "Test passed status with ignore sub status and info", | ||
status: apis.StatusPassed, | ||
subStatus: apis.SubStatusException, | ||
info: string(apis.SubStatusConfigurationInfo), | ||
wantStatus: apis.StatusPassed, | ||
wantSubStatus: apis.SubStatusException, | ||
wantInfo: string(apis.SubStatusConfigurationInfo), | ||
}, | ||
{ | ||
name: "Test failed status and info", | ||
status: apis.StatusFailed, | ||
subStatus: "", | ||
info: string(apis.SubStatusManualReviewInfo), | ||
wantStatus: apis.StatusFailed, | ||
wantSubStatus: "", | ||
wantInfo: string(apis.SubStatusManualReviewInfo), | ||
}, | ||
{ | ||
name: "Test skipped status with irrelevant sub status without info", | ||
status: apis.StatusSkipped, | ||
subStatus: apis.SubStatusConfiguration, | ||
info: "", | ||
wantStatus: apis.StatusSkipped, | ||
wantSubStatus: apis.SubStatusConfiguration, | ||
wantInfo: "", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
s := NewStatusInfo(tt.status, tt.subStatus, tt.info) | ||
if got := s.Status(); got != tt.wantStatus { | ||
t.Errorf("NewStatusInfo().Status() = %v, want %v", got, tt.wantStatus) | ||
} | ||
if got := s.GetSubStatus(); got != tt.wantSubStatus { | ||
t.Errorf("NewStatusInfo().GetSubStatus() = %v, want %v", got, tt.wantSubStatus) | ||
} | ||
if got := s.Info(); got != tt.wantInfo { | ||
t.Errorf("NewStatusInfo().Info() = %v, want %v", got, tt.wantInfo) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGetSubStatus(t *testing.T) { | ||
status := &Status{subStatus: apis.SubStatusIntegration} | ||
if status.GetSubStatus() != apis.SubStatusIntegration { | ||
t.Errorf("Expected subStatus to be %s, got %s", apis.SubStatusIntegration, status.GetSubStatus()) | ||
} | ||
} | ||
|
||
func TestStatus(t *testing.T) { | ||
status := &Status{status: apis.StatusFailed} | ||
if status.Status() != apis.StatusFailed { | ||
t.Errorf("Expected status to be %s, got %s", apis.StatusFailed, status.Status()) | ||
} | ||
} | ||
|
||
func TestInfo(t *testing.T) { | ||
status := &Status{} | ||
if status.Info() != "" { | ||
t.Errorf("Expected Info to be empty string, got %s", status.Info()) | ||
} | ||
} | ||
|
||
func TestIsPassed(t *testing.T) { | ||
status := &Status{status: apis.StatusPassed} | ||
if !status.IsPassed() { | ||
t.Errorf("Expected IsPassed to be true, got false") | ||
} | ||
} | ||
|
||
func TestIsFailed(t *testing.T) { | ||
status := &Status{status: apis.StatusFailed} | ||
if !status.IsFailed() { | ||
t.Errorf("Expected IsFailed to be true, got false") | ||
} | ||
} | ||
|
||
func TestIsSkipped(t *testing.T) { | ||
status := &Status{status: apis.StatusSkipped} | ||
if !status.IsSkipped() { | ||
t.Errorf("Expected IsSkipped to be true, got false") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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