Skip to content

Commit

Permalink
πŸ”„ synced file(s) with bosch-grow-pat/onyx (#6)
Browse files Browse the repository at this point in the history
* πŸ”„ created local 'onyx/.vscode/' from remote '.vscode/'

* πŸ”„ synced local 'onyx/pkg/' with remote 'pkg/'

* πŸ”„ synced local 'onyx/cmd/' with remote 'cmd/'

* πŸ”„ synced local 'onyx/internal/' with remote 'internal/'

* πŸ”„ synced local 'onyx/Makefile' with remote 'Makefile'

* running gazelle: `gazelle -go_prefix github.com/B-S-F/yaku`

---------

Co-authored-by: bsf-sync-bot[bot] <180526808+bsf-sync-bot[bot]@users.noreply.github.com>
Co-authored-by: Frank Bernhardt <[email protected]>
  • Loading branch information
bsf-sync-bot[bot] and frank-bee authored Oct 15, 2024
1 parent 22f61ed commit 1ad9254
Show file tree
Hide file tree
Showing 47 changed files with 610 additions and 345 deletions.
4 changes: 2 additions & 2 deletions chart/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports_files(["Chart.lock"])
helm_chart(
name = "yaku_helm",
chart = "Chart.yaml",
registry_url = "oci://ghcr.io/b-s-f/charts/",
values = "values.yaml",
images = [
"//core-image:push-image",
],
registry_url = "oci://ghcr.io/b-s-f/charts/",
values = "values.yaml",
deps = [
"@helm_dep_argo_workflows",
"@helm_dep_minio",
Expand Down
4 changes: 2 additions & 2 deletions core-image/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

# Put app go_binary into a tar layer.
Expand Down Expand Up @@ -84,4 +84,4 @@ oci_push(
# # Use the image built for the exec platform rather than the target platform
# image = ":image",
# tags = ["requires-docker"],
#)
#)
49 changes: 49 additions & 0 deletions onyx/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Exec",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/cli/main.go",
"cwd": "${workspaceFolder}",
"args": [
"exec",
"${workspaceFolder}/examples",
"--output-dir=${workspaceFolder}/output",
"--check-timeout=5"
],
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Schema",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/cli/main.go",
"cwd": "${workspaceFolder}",
"args": [
"schema",
],
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Migrate",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/cli/main.go",
"cwd": "${workspaceFolder}",
"args": [
"migrate",
"${workspaceFolder}/examples/old-qg-config.yaml",
"--output=${workspaceFolder}/examples/new-qg-config.yaml"
],
"envFile": "${workspaceFolder}/.env"
},
]
}
10 changes: 10 additions & 0 deletions onyx/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
],
"go.testTags": "unit,integration",
"gopls": {
"buildFlags": ["-tags=unit,integration"],
}
}
2 changes: 1 addition & 1 deletion onyx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fmt:

.PHONY: setup
setup:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
go install github.com/axw/gocov/[email protected]
go install github.com/AlekSi/gocov-xml@latest
go install github.com/jstemmer/go-junit-report/v2@latest
Expand Down
155 changes: 154 additions & 1 deletion onyx/cmd/cli/exec/exec_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (

"github.com/B-S-F/yaku/onyx/internal/onyx/exec"
"github.com/B-S-F/yaku/onyx/pkg/helper"
resultv2 "github.com/B-S-F/yaku/onyx/pkg/v2/result"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

var (
Expand Down Expand Up @@ -67,7 +70,20 @@ func TestExecCommandIntegration(t *testing.T) {
t.Fatal(err)
}
want := helper.GoldenValue(t, goldenPath, replacedGot, *update)
assert.YAMLEq(t, string(want), string(replacedGot))

assert.Equal(t, len(want), len(replacedGot))
switch version {
case "v2":
var wantResult, gotResult resultv2.Result
err := yaml.Unmarshal(want, &wantResult)
require.NoError(t, err)
err = yaml.Unmarshal(replacedGot, &gotResult)
require.NoError(t, err)

compareResults(t, &wantResult, &gotResult)
case "v1":
assert.YAMLEq(t, string(want), string(replacedGot))
}
})
}
}
Expand All @@ -81,3 +97,140 @@ func serveApps(directory string, port string, t *testing.T) {
}
}()
}

func compareResults(t *testing.T, result1, result2 *resultv2.Result) {
assert.Equal(t, result1.Metadata.Version, result1.Metadata.Version, "Metadata versions should be equal")
compareHeader(t, result1.Header, result2.Header)
assert.Equal(t, result1.OverallStatus, result2.OverallStatus, "OverallStatus should be equal")
compareStatistics(t, result1.Statistics, result2.Statistics)

assert.Equal(t, len(result1.Chapters), len(result2.Chapters), "Number of chapters should be equal")
for chapterKey, chapter1 := range result1.Chapters {
chapter2, chapterExists := result2.Chapters[chapterKey]
assert.True(t, chapterExists, "Chapter %s should exist in both results", chapterKey)
compareChapters(t, chapter1, chapter2, chapterKey)
}

if result1.Finalize != nil && result2.Finalize != nil {
compareFinalize(t, result1.Finalize, result2.Finalize)
}
}

func compareHeader(t *testing.T, header1, header2 resultv2.Header) {
assert.Equal(t, header1.Name, header2.Name, "Header names should be equal")
assert.Equal(t, header1.Version, header2.Version, "Header versions should be equal")
assert.Equal(t, header1.Date, header2.Date, "Header dates should be equal")
assert.Equal(t, header1.ToolVersion, header2.ToolVersion, "Header tool versions should be equal")
}

func compareStatistics(t *testing.T, stats1, stats2 resultv2.Statistics) {
assert.Equal(t, stats1.CountChecks, stats2.CountChecks, "Counted checks should be equal")
assert.Equal(t, stats1.CountAutomatedChecks, stats2.CountAutomatedChecks, "Counted automated checks should be equal")
assert.Equal(t, stats1.CountManualChecks, stats2.CountManualChecks, "Counted manual checks should be equal")
assert.Equal(t, stats1.CountUnansweredChecks, stats2.CountUnansweredChecks, "Counted unanswered checks should be equal")
assert.Equal(t, stats1.CountSkippedChecks, stats2.CountSkippedChecks, "Counted skipped checks should be equal")
assert.Equal(t, stats1.PercentageAutomated, stats2.PercentageAutomated, "Degree of automation should be equal")
assert.Equal(t, stats1.PercentageDone, stats2.PercentageDone, "Degree of completion should be equal")
}

func compareChapters(t *testing.T, chapter1, chapter2 *resultv2.Chapter, chapterKey string) {
assert.True(t, chapter1 != nil && chapter2 != nil)
assert.Equal(t, chapter1.Title, chapter2.Title, "Chapter %s titles should be equal", chapterKey)
assert.Equal(t, chapter1.Status, chapter2.Status, "Chapter %s status should be equal", chapterKey)
assert.Equal(t, chapter1.Text, chapter2.Text, "Chapter %s text should be equal", chapterKey)

assert.Equal(t, len(chapter1.Requirements), len(chapter2.Requirements), "Number of requirements should be equal for chapter %s", chapterKey)
for reqKey, req1 := range chapter1.Requirements {
req2, reqExists := chapter2.Requirements[reqKey]
assert.True(t, reqExists, "Requirement %s should exist in both results for chapter %s", reqKey, chapterKey)
compareRequirements(t, req1, req2, reqKey, chapterKey)
}
}

func compareRequirements(t *testing.T, req1, req2 *resultv2.Requirement, reqKey, chapterKey string) {
assert.Equal(t, req1.Title, req2.Title, "Requirement %s titles should be equal in chapter %s", reqKey, chapterKey)
assert.Equal(t, req1.Text, req2.Text, "Requirement %s texts should be equal in chapter %s", reqKey, chapterKey)
assert.Equal(t, req1.Status, req2.Status, "Requirement %s status should be equal in chapter %s", reqKey, chapterKey)

assert.Equal(t, len(req1.Checks), len(req2.Checks), "Number of checks should be equal for requirement %s in chapter %s", reqKey, chapterKey)
for checkKey, check1 := range req1.Checks {
check2, checkExists := req2.Checks[checkKey]
assert.True(t, checkExists, "Check %s should exist in both requirements for chapter %s", checkKey, chapterKey)
compareChecks(t, check1, check2, checkKey, reqKey, chapterKey)
}
}

func compareChecks(t *testing.T, check1, check2 *resultv2.Check, checkKey, reqKey, chapterKey string) {
assert.Equal(t, check1.Title, check2.Title, "Check %s titles should be equal in requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, check1.Type, check2.Type, "Check %s type should be equal in requirement %s of chapter %s", checkKey, reqKey, chapterKey)

assert.Equal(t, len(check1.Autopilots), len(check2.Autopilots), "Number of autopilots should be equal for check %s in requirement %s of chapter %s", checkKey, reqKey, chapterKey)
for i := range check1.Autopilots {
compareAutopilots(t, check1.Autopilots[i], check2.Autopilots[i], checkKey, reqKey, chapterKey)
}

compareEvaluation(t, check1.Evaluation, check2.Evaluation, checkKey, reqKey, chapterKey)
}

func compareAutopilots(t *testing.T, auto1, auto2 resultv2.Autopilot, checkKey, reqKey, chapterKey string) {
assert.Equal(t, auto1.Name, auto2.Name, "Autopilot names should be equal for check %s in requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, len(auto1.Steps), len(auto2.Steps), "Number of steps should be equal for autopilot in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)

for i := range auto1.Steps {
compareSteps(t, auto1.Steps[i], auto2.Steps[i], checkKey, reqKey, chapterKey)
}
}

func compareSteps(t *testing.T, step1, step2 resultv2.Step, checkKey, reqKey, chapterKey string) {
assert.Equal(t, step1.Title, step2.Title, "Step titles should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.Id, step2.Id, "Step ids should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.Depends, step2.Depends, "Step dependencies should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
compareLogs(t, step1.Logs, step2.Logs, "Step logs should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.Warnings, step2.Warnings, "Step Warnings should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.Messages, step2.Messages, "Step Messages should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.ConfigFiles, step2.ConfigFiles, "Step config files should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.OutputDir, step2.OutputDir, "Step output dirs should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.ResultFile, step2.ResultFile, "Step result files should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.InputDirs, step2.InputDirs, "Step input dirs should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, step1.ExitCode, step2.ExitCode, "Step exit codes should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
}

func compareEvaluation(t *testing.T, eval1, eval2 resultv2.Evaluation, checkKey, reqKey, chapterKey string) {
assert.Equal(t, eval1.Status, eval2.Status, "Evaluation status should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, eval1.Reason, eval2.Reason, "Evaluation reason should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)

assert.Equal(t, len(eval1.Results), len(eval2.Results), "Number of results should be equal for evaluation in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
for i := range eval1.Results {
compareEvaluationResults(t, eval1.Results[i], eval2.Results[i], checkKey, reqKey, chapterKey)
}

compareLogs(t, eval1.Logs, eval2.Logs, "Evaluation logs should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, eval1.Warnings, eval2.Warnings, "Evaluation warnings should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, eval1.Messages, eval2.Messages, "Evaluation messages should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, eval1.ConfigFiles, eval2.ConfigFiles, "Evaluation config files should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, eval1.ExitCode, eval2.ExitCode, "Evaluation exit codes should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
}

func compareEvaluationResults(t *testing.T, result1, result2 resultv2.EvaluationResult, checkKey, reqKey, chapterKey string) {
assert.Equal(t, result1.Hash, result2.Hash, "Result hash should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, result1.Criterion, result2.Criterion, "Result criterion should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, result1.Fulfilled, result2.Fulfilled, "Result fulfillment should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, result1.Justification, result2.Justification, "Result justification should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
assert.Equal(t, result1.Metadata, result2.Metadata, "Result metadata should be equal in check %s, requirement %s of chapter %s", checkKey, reqKey, chapterKey)
}

func compareFinalize(t *testing.T, finalize1, finalize2 *resultv2.Finalize) {

compareLogs(t, finalize1.Logs, finalize2.Logs, "Finalize logs should be equal")
assert.Equal(t, finalize1.Warnings, finalize2.Warnings, "Finalize warnings should be equal")
assert.Equal(t, finalize1.Messages, finalize2.Messages, "Finalize messages should be equal")
assert.Equal(t, finalize1.ConfigFiles, finalize2.ConfigFiles, "Finalize config files should be equal")
assert.Equal(t, finalize1.ExitCode, finalize2.ExitCode, "Finalize exit codes should be equal")
}

func compareLogs(t *testing.T, logs1, logs2 []string, msgAndArgs ...interface{}) {
assert.Equal(t, len(logs1), len(logs2), append(msgAndArgs, "Log count should be equal")...)
for i := range logs1 {
assert.JSONEq(t, logs1[i], logs2[i], append(msgAndArgs, "Log %d should match", i)...)
}
}
2 changes: 1 addition & 1 deletion onyx/cmd/cli/exec/testdata/v2/configuration/qg-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ autopilots:
special-output-provider:
evaluate:
run: |
echo '{"result": {"criterion": "FFixed RTC ticket with ID 1588653 must be risk assessed", "fulfilled": false, "justification": "Please type the appropriate risk assessment for RTC Ticket with ID 1588653.", "metadata": {"Summary": "[main] after EDLminidump SoC bootup stuck"}}}'
echo '{"result": {"criterion": "FFixed RTC ticket with ID 1588653 must be risk assessed", "fulfilled": false, "justification": "Please type the appropriate risk assessment for RTC Ticket with ID 1588653.", "metadata": {"Id": 1588653, "Filed Against": "Platform_General", "Summary": "[main] after EDLminidump SoC bootup stuck", "Creation Date": "2022-11-08T09:51:00", "Modified Date": "2023-06-09T14:05:00", "Defect Occurrence": "Always", "boolean": true, "test-json": {"key": "value"}}}}'
echo '{"status": "RED", "reason": "test"}'
status-provider:
evaluate:
Expand Down
11 changes: 9 additions & 2 deletions onyx/cmd/cli/exec/testdata/v2/configuration/qg-result.golden
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ chapters:
- fetch1
logs:
- '{"source":"stdout","text":"1_1_1"}'
- '{"source":"stdout","text":"evidences/1_1_1/steps/fetch2/files"}'
- '{"text":"evidences/1_1_1/steps/fetch2/files","source":"stdout"}'
- '{"source":"stdout","text":"evidences/1_1_1/steps/fetch2/data.json"}'
- '{"source":"stdout","text":"evidences/1_1_1/steps/fetch1/files"}'
configFiles: []
Expand Down Expand Up @@ -718,9 +718,16 @@ chapters:
fulfilled: false
justification: Please type the appropriate risk assessment for RTC Ticket with ID 1588653.
metadata:
Creation Date: "2022-11-08T09:51:00"
Modified Date: "2023-06-09T14:05:00"
Defect Occurrence: "Always"
boolean: "true"
test-json: "{\"key\":\"value\"}"
Id: "1588653"
Filed Against: "Platform_General"
Summary: "[main] after EDLminidump SoC bootup stuck"
logs:
- '{"source":"stdout","json":{"result":{"criterion":"FFixed RTC ticket with ID 1588653 must be risk assessed","fulfilled":false,"justification":"Please type the appropriate risk assessment for RTC Ticket with ID 1588653.","metadata":{"Summary":"[main] after EDLminidump SoC bootup stuck"}}}}'
- '{"source":"stdout","json":{"result":{"criterion":"FFixed RTC ticket with ID 1588653 must be risk assessed","fulfilled":false,"justification":"Please type the appropriate risk assessment for RTC Ticket with ID 1588653.","metadata":{"Id":1588653,"Filed Against":"Platform_General","Summary":"[main] after EDLminidump SoC bootup stuck","Creation Date":"2022-11-08T09:51:00","Modified Date":"2023-06-09T14:05:00","Defect Occurrence":"Always","boolean":true,"test-json":{"key":"value"}}}}}'
- '{"source":"stdout","json":{"reason":"test","status":"RED"}}'
finalize:
logs:
Expand Down
2 changes: 1 addition & 1 deletion onyx/cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/spf13/viper"
)

const version = "0.11.1"
const version = "0.12.0"

var (
logLevel = "log-level"
Expand Down
4 changes: 2 additions & 2 deletions onyx/cmd/cli/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func Run(cmd *cobra.Command, args []string) error {
version := viper.GetString("target-version")
output := viper.GetString("output")
filepath := filepath.Clean(args[0])
logger.Set(logger.NewCommon(logger.Settings{
File: "onyx.log",
logger.Set(logger.NewConsoleFileLogger(logger.Settings{
Files: []string{"onyx.log"},
}))
return onyx.Migrate(version, filepath, output)
}
4 changes: 2 additions & 2 deletions onyx/cmd/cli/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func Run(cmd *cobra.Command, args []string) error {
_ = viper.BindPFlag("output", cmd.Flags().Lookup("output"))
version := viper.GetString("version")
output := viper.GetString("output")
logger.Set(logger.NewCommon(logger.Settings{
File: "onyx.log",
logger.Set(logger.NewConsoleFileLogger(logger.Settings{
Files: []string{"onyx.log"},
}))
return onyx.Schema(kind, version, output)
}
Expand Down
Loading

0 comments on commit 1ad9254

Please sign in to comment.