Skip to content

Commit 8e97b9c

Browse files
committed
raw doggen output with lint
1 parent dfd5a13 commit 8e97b9c

File tree

226 files changed

+266317
-652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+266317
-652
lines changed

cmd/certsuite/check/check.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ var (
1313
}
1414
)
1515

16+
// NewCommand Creates a check command that aggregates image certification and result verification actions
17+
//
18+
// This function builds a new Cobra command for the tool’s check
19+
// functionality. It registers two child commands: one to verify image
20+
// certificates and another to validate test results against expected outputs or
21+
// logs. The resulting command is returned for inclusion in the main CLI
22+
// hierarchy.
1623
func NewCommand() *cobra.Command {
1724
checkCmd.AddCommand(imagecert.NewCommand())
1825
checkCmd.AddCommand(results.NewCommand())

cmd/certsuite/check/image_cert_status/image_cert_status.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ var checkImageCertStatusCmd = &cobra.Command{
3030
RunE: checkImageCertStatus,
3131
}
3232

33+
// checkImageCertStatus checks whether a container image is certified
34+
//
35+
// The function reads command-line flags for an image name, registry, tag, or
36+
// digest, then uses a validator from the certdb package to determine
37+
// certification status. It prints formatted information about the selected
38+
// image and outputs a colored result indicating success or failure. Errors are
39+
// returned if required parameters are missing or if the validator cannot be
40+
// obtained.
3341
func checkImageCertStatus(cmd *cobra.Command, _ []string) error {
3442
imageName, _ := cmd.Flags().GetString("name")
3543
imageRegistry, _ := cmd.Flags().GetString("registry")
@@ -64,6 +72,13 @@ func checkImageCertStatus(cmd *cobra.Command, _ []string) error {
6472
return nil
6573
}
6674

75+
// NewCommand configures and returns the image certificate status command
76+
//
77+
// This function sets up persistent flags for specifying an image name,
78+
// registry, tag, digest, and an optional offline database path. It enforces
79+
// that a name and registry must be provided together while ensuring the name
80+
// and digest cannot both be set at once. Finally, it returns the fully
81+
// configured command object.
6782
func NewCommand() *cobra.Command {
6883
checkImageCertStatusCmd.PersistentFlags().String("name", "", "name of the image to verify")
6984
checkImageCertStatusCmd.PersistentFlags().String("registry", "", "registry where the image is stored")

cmd/certsuite/check/results/results.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@ const (
2626
resultMiss = "MISSING"
2727
)
2828

29+
// TestCaseList Stores the names of test cases categorized by outcome
30+
//
31+
// This structure keeps three slices, each holding strings that represent test
32+
// case identifiers. The Pass slice lists all tests that succeeded, Fail
33+
// contains those that failed, and Skip holds tests that were not executed. It
34+
// is used to report results in a concise format.
2935
type TestCaseList struct {
3036
Pass []string `yaml:"pass"`
3137
Fail []string `yaml:"fail"`
3238
Skip []string `yaml:"skip"`
3339
}
3440

41+
// TestResults Holds a collection of test case results
42+
//
43+
// This structure contains a slice of individual test case outcomes, allowing
44+
// the program to group related results together. The embedded field
45+
// automatically inherits all fields and methods from the underlying test case
46+
// list type, enabling direct access to the collection’s elements. It serves
47+
// as a container for serializing or reporting aggregated test data.
3548
type TestResults struct {
3649
TestCaseList `yaml:"testCases"`
3750
}
@@ -42,6 +55,14 @@ var checkResultsCmd = &cobra.Command{
4255
RunE: checkResults,
4356
}
4457

58+
// checkResults compares recorded test outcomes against a reference template
59+
//
60+
// The function reads actual test results from a log file, optionally generates
61+
// a YAML template of those results, or loads expected results from an existing
62+
// template. It then checks each test case for mismatches between actual and
63+
// expected values, reporting any discrepancies in a formatted table and
64+
// terminating the program if differences are found. If all results match, it
65+
// prints a success message.
4566
func checkResults(cmd *cobra.Command, _ []string) error {
4667
templateFileName, _ := cmd.Flags().GetString("template")
4768
generateTemplate, _ := cmd.Flags().GetBool("generate-template")
@@ -90,6 +111,13 @@ func checkResults(cmd *cobra.Command, _ []string) error {
90111
return nil
91112
}
92113

114+
// getTestResultsDB Parses a log file to build a test result map
115+
//
116+
// The function opens the specified log file, reads it line by line, and
117+
// extracts test case names and their recorded results using a regular
118+
// expression. Each matched pair is stored in a map where the key is the test
119+
// case name and the value is its result string. It returns this map along with
120+
// an error if any step fails.
93121
func getTestResultsDB(logFileName string) (map[string]string, error) {
94122
resultsDB := make(map[string]string)
95123

@@ -124,6 +152,13 @@ func getTestResultsDB(logFileName string) (map[string]string, error) {
124152
return resultsDB, nil
125153
}
126154

155+
// getExpectedTestResults loads expected test outcomes from a YAML template
156+
//
157+
// The function reads a specified file, decodes its YAML content into a
158+
// structured list of test cases classified as pass, skip, or fail, then builds
159+
// a map associating each case with the corresponding result string. It returns
160+
// this map along with any error that occurs during file reading or
161+
// unmarshalling.
127162
func getExpectedTestResults(templateFileName string) (map[string]string, error) {
128163
templateFile, err := os.ReadFile(templateFileName)
129164
if err != nil {
@@ -150,6 +185,14 @@ func getExpectedTestResults(templateFileName string) (map[string]string, error)
150185
return expectedTestResults, nil
151186
}
152187

188+
// printTestResultsMismatch Displays a formatted table of test cases that did not match the expected results
189+
//
190+
// The function receives a list of mismatched test case identifiers along with
191+
// maps of actual and expected outcomes. It prints a header, then iterates over
192+
// each mismatched case, retrieving the corresponding expected and actual
193+
// values—using a placeholder when either is missing—and outputs them in
194+
// aligned columns. Finally, it draws separators to delineate each row for
195+
// readability.
153196
func printTestResultsMismatch(mismatchedTestCases []string, actualResults, expectedResults map[string]string) {
154197
fmt.Printf("\n")
155198
fmt.Println(strings.Repeat("-", 96)) //nolint:mnd // table line
@@ -169,6 +212,14 @@ func printTestResultsMismatch(mismatchedTestCases []string, actualResults, expec
169212
}
170213
}
171214

215+
// generateTemplateFile Creates a YAML template file summarizing test case outcomes
216+
//
217+
// This function takes a map of test cases to result strings and builds a
218+
// structured template containing lists for passed, skipped, and failed tests.
219+
// It encodes the structure into YAML with two-space indentation and writes it
220+
// to a predefined file path with specific permissions. If an unknown result
221+
// value is encountered or any I/O operation fails, it returns an error
222+
// detailing the issue.
172223
func generateTemplateFile(resultsDB map[string]string) error {
173224
var resultsTemplate TestResults
174225
for testCase, result := range resultsDB {
@@ -201,6 +252,12 @@ func generateTemplateFile(resultsDB map[string]string) error {
201252
return nil
202253
}
203254

255+
// NewCommand Creates a command for checking test results against expected templates
256+
//
257+
// It defines persistent flags for specifying the template file, log file, and
258+
// an option to generate a new template from logs. The flags are mutually
259+
// exclusive to avoid conflicting inputs. Finally, it returns the configured
260+
// command instance.
204261
func NewCommand() *cobra.Command {
205262
checkResultsCmd.PersistentFlags().String("template", "expected_results.yaml", "reference YAML template with the expected results")
206263
checkResultsCmd.PersistentFlags().String("log-file", "certsuite.log", "log file of the Certsuite execution")

cmd/certsuite/claim/claim.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ var (
1313
}
1414
)
1515

16+
// NewCommand Creates a subcommand for claim operations
17+
//
18+
// It initializes the claim command by attaching its compare and show
19+
// subcommands, each of which provides functionality for comparing claim files
20+
// or displaying claim information. The function returns the configured
21+
// cobra.Command ready to be added to the main application root command.
1622
func NewCommand() *cobra.Command {
1723
claimCommand.AddCommand(compare.NewCommand())
1824
claimCommand.AddCommand(show.NewCommand())

cmd/certsuite/claim/compare/compare.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ var (
8686
}
8787
)
8888

89+
// NewCommand Creates a command for comparing two claim files
90+
//
91+
// It defines flags for the paths of two existing claim files, marks both as
92+
// required, and handles errors by logging them before returning nil if marking
93+
// fails. The function then returns the configured command object for use in the
94+
// CLI.
8995
func NewCommand() *cobra.Command {
9096
claimCompareFiles.Flags().StringVarP(
9197
&Claim1FilePathFlag, "claim1", "1", "",
@@ -109,6 +115,13 @@ func NewCommand() *cobra.Command {
109115
return claimCompareFiles
110116
}
111117

118+
// claimCompare compares two claim files for differences
119+
//
120+
// This function reads the paths provided by global flags, loads each file,
121+
// unmarshals them into claim structures, and then generates diff reports for
122+
// versions, test cases, configurations, and nodes. The resulting diffs are
123+
// printed to standard output. If any step fails, it logs a fatal error and
124+
// exits.
112125
func claimCompare(_ *cobra.Command, _ []string) error {
113126
err := claimCompareFilesfunc(Claim1FilePathFlag, Claim2FilePathFlag)
114127
if err != nil {
@@ -117,6 +130,13 @@ func claimCompare(_ *cobra.Command, _ []string) error {
117130
return nil
118131
}
119132

133+
// claimCompareFilesfunc Reads two claim files, unmarshals them, and outputs structured comparison reports
134+
//
135+
// The function loads the contents of two specified claim files and parses each
136+
// JSON document into a claim schema structure. It then generates separate diff
137+
// reports for the claim versions, test case results, configuration differences,
138+
// and node details, printing each report to standard output. Errors during file
139+
// reading or unmarshalling are wrapped with context and returned for handling.
120140
func claimCompareFilesfunc(claim1, claim2 string) error {
121141
// readfiles
122142
claimdata1, err := os.ReadFile(claim1)
@@ -161,6 +181,12 @@ func claimCompareFilesfunc(claim1, claim2 string) error {
161181
return nil
162182
}
163183

184+
// unmarshalClaimFile Parses raw claim data into a structured schema
185+
//
186+
// This function receives raw JSON bytes representing a claim file, attempts to
187+
// unmarshal them into the claim.Schema type, and returns either the populated
188+
// struct or an error if parsing fails. It uses standard library JSON decoding
189+
// and propagates any unmarshaling errors back to the caller.
164190
func unmarshalClaimFile(claimdata []byte) (claim.Schema, error) {
165191
var claimDataResult claim.Schema
166192
err := json.Unmarshal(claimdata, &claimDataResult)

cmd/certsuite/claim/compare/configurations/configurations.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@ import (
77
"github.com/redhat-best-practices-for-k8s/certsuite/cmd/certsuite/pkg/claim"
88
)
99

10+
// AbnormalEventsCount Displays counts of abnormal events for two claims
11+
//
12+
// This struct holds integer counts of abnormal events for two distinct claims,
13+
// named Claim1 and Claim2. The String method formats these values into a
14+
// readable table with headers, producing a string that summarizes the event
15+
// counts for comparison purposes.
1016
type AbnormalEventsCount struct {
1117
Claim1 int `json:"claim1"`
1218
Claim2 int `json:"claim2"`
1319
}
1420

21+
// AbnormalEventsCount.String Formats abnormal event counts for two claims
22+
//
23+
// This method builds a multi-line string that displays the number of abnormal
24+
// events detected in two separate claims. It starts with a header line, then
25+
// adds a formatted table row showing the claim identifiers and their
26+
// corresponding counts using printf-style formatting. The resulting string is
27+
// returned for display or logging.
1528
func (c *AbnormalEventsCount) String() string {
1629
const (
1730
rowHeaderFmt = "%-12s%-s\n"
@@ -25,11 +38,25 @@ func (c *AbnormalEventsCount) String() string {
2538
return str
2639
}
2740

41+
// DiffReport captures configuration differences and abnormal event counts
42+
//
43+
// This structure contains a diff of Cert Suite configuration objects and a
44+
// count of abnormal events for two claims. The Config field holds the result
45+
// from a diff comparison, while AbnormalEvents stores how many abnormal events
46+
// each claim reported. It is used to report and display discrepancies between
47+
// claims.
2848
type DiffReport struct {
2949
Config *diff.Diffs `json:"CertSuiteConfig"`
3050
AbnormalEvents AbnormalEventsCount `json:"abnormalEventsCount"`
3151
}
3252

53+
// DiffReport.String Formats the diff report into a readable string
54+
//
55+
// This method builds a formatted representation of a configuration comparison,
56+
// beginning with header lines and then appending the configuration details
57+
// followed by any abnormal events. It concatenates strings from the embedded
58+
// Config and AbnormalEvents fields and returns the final result as a single
59+
// string.
3360
func (d *DiffReport) String() string {
3461
str := "CONFIGURATIONS\n"
3562
str += "--------------\n\n"
@@ -42,6 +69,13 @@ func (d *DiffReport) String() string {
4269
return str
4370
}
4471

72+
// GetDiffReport Creates a report of configuration differences
73+
//
74+
// The function compares two configuration objects from claim files, generating
75+
// a DiffReport that includes field-by-field differences in the main
76+
// configuration map and counts of abnormal events present in each file. It uses
77+
// an external diff utility to compute the detailed comparison and returns the
78+
// assembled report for further processing or display.
4579
func GetDiffReport(claim1Configurations, claim2Configurations *claim.Configurations) *DiffReport {
4680
return &DiffReport{
4781
Config: diff.Compare("Cert Suite Configuration", claim1Configurations.Config, claim2Configurations.Config, nil),

cmd/certsuite/claim/compare/diff/diff.go

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import (
88
"strings"
99
)
1010

11-
// Diffs holds the differences between two interface{} objects that have
12-
// been obtained by unmarshalling JSON strings.
11+
// Diffs Captures differences between two JSON objects
12+
//
13+
// This structure records fields that differ, as well as those present only in
14+
// one of the compared claims. It stores the object name for contextual output
15+
// and provides a method to format the differences into a readable table. The
16+
// fields are populated by comparing flattened representations of each claim.
1317
type Diffs struct {
1418
// Name of the json object whose diffs are stored here.
1519
// It will be used when serializing the data in table format.
@@ -21,32 +25,25 @@ type Diffs struct {
2125
FieldsInClaim2Only []string
2226
}
2327

24-
// FieldDIff holds the field path and the values from both claim files
25-
// that have been found to be different.
28+
// FieldDiff Represents a mismatch between two claim files
29+
//
30+
// This structure records the location of a differing field along with its value
31+
// from each claim file. It is used during comparison to track which fields
32+
// differ, enabling further processing or reporting. The field path indicates
33+
// where in the document the discrepancy occurs.
2634
type FieldDiff struct {
2735
FieldPath string `json:"field"`
2836
Claim1Value interface{} `json:"claim1Value"`
2937
Claim2Value interface{} `json:"claim2Value"`
3038
}
3139

32-
// Stringer method. The output string is a table like this:
33-
// <name>: Differences
34-
// FIELD CLAIM 1 CLAIM 2
35-
// /jsonpath/to/field1 value1 value2
36-
// /jsonpath/to/another/field2 value3 value4
37-
// ...
38-
//
39-
// <name>: Only in CLAIM 1
40-
// /jsonpath/to/field/in/claim1/only
41-
// ...
42-
//
43-
// <name>: Only in CLAIM 2
44-
// /jsonpath/to/field/in/claim2/only
45-
// ...
40+
// Diffs.String Formats a readable report of claim differences
4641
//
47-
// Where <name> is replaced by the value of d.Name.
48-
// The columns "FIELD" and "CLAIM 1" have a dynamic width that depends
49-
// on the longest field path and longest value.
42+
// The method builds a string that lists fields with differing values between
43+
// two claims, as well as fields present only in one claim or the other. It
44+
// calculates column widths based on longest field paths and values to align the
45+
// table neatly. If no differences exist it displays a placeholder indicating
46+
// none were found.
5047
func (d *Diffs) String() string {
5148
const (
5249
noDiffs = "<none>"
@@ -110,13 +107,13 @@ func (d *Diffs) String() string {
110107
return str
111108
}
112109

113-
// Compares to interface{} objects obtained through json.Unmarshal() and returns
114-
// a pointer to a Diffs object.
115-
// A simple filtering of json subtrees can be achieved using the filters slice parameter.
116-
// This might be helpful with big json trees that could have too many potential differences,
117-
// but we want to get just the differences for some custom nodes/subtrees.
118-
// E.g.: filters = []string{"labels"} : only the nodes/subtrees under all the
119-
// labels nodes/branches will be traversed and compared.
110+
// Compare Compares two JSON structures for differences
111+
//
112+
// This function takes two interface values that were previously unmarshaled
113+
// from JSON, walks each tree to collect paths and values, then compares
114+
// corresponding entries. It records mismatched values, fields present only in
115+
// the first object, and fields present only in the second. Optional filters
116+
// allow limiting comparison to specified subtrees.
120117
func Compare(objectName string, claim1Object, claim2Object interface{}, filters []string) *Diffs {
121118
objectsDiffs := Diffs{Name: objectName}
122119

@@ -163,13 +160,24 @@ func Compare(objectName string, claim1Object, claim2Object interface{}, filters
163160
return &objectsDiffs
164161
}
165162

163+
// field represents a node in the traversal result
164+
//
165+
// This structure holds the full path to a value and the value itself as
166+
// encountered during tree walking. The Path string records the hierarchical
167+
// location using delimiters, while Value captures any type of data found at
168+
// that point. It is used by the traversal routine to aggregate matching fields
169+
// for comparison.
166170
type field struct {
167171
Path string
168172
Value interface{}
169173
}
170174

171-
// Helper function that traverses recursively a node to return a list
172-
// of each field (leaf) path and its value.
175+
// traverse recursively collects leaf paths and values from a nested data structure
176+
//
177+
// The function walks through maps, slices, or simple values, building a path
178+
// string for each leaf node separated by slashes. It optionally filters the
179+
// collected fields based on provided substrings in the path. The result is a
180+
// slice of field structs containing the full path and the corresponding value.
173181
func traverse(node interface{}, path string, filters []string) []field {
174182
if node == nil {
175183
return nil

0 commit comments

Comments
 (0)