Skip to content

Commit 9bde9f6

Browse files
committed
Revert "test doc"
This reverts commit 82f9b7b.
1 parent 34b4ada commit 9bde9f6

File tree

135 files changed

+671
-73094
lines changed

Some content is hidden

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

135 files changed

+671
-73094
lines changed

cmd/certsuite/check/check.go

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

16-
// NewCommand creates the root check command.
17-
//
18-
// It constructs a new cobra.Command instance configured for the certsuite
19-
// checking functionality. The returned command is ready to have subcommands
20-
// added to it and can be executed as part of the certsuite CLI. No arguments
21-
// are required; the function returns a pointer to the created *cobra.Command.
2216
func NewCommand() *cobra.Command {
2317
checkCmd.AddCommand(imagecert.NewCommand())
2418
checkCmd.AddCommand(results.NewCommand())

cmd/certsuite/check/image_cert_status/image_cert_status.go

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

33-
// checkImageCertStatus retrieves image information from flags, validates it,
34-
// checks whether the container is certified, and prints the status.
35-
//
36-
// It expects command-line flags for registry, namespace, repository, and tag,
37-
// which are obtained via GetString on the cobra.Command flags.
38-
// The function validates these inputs, then calls IsContainerCertified
39-
// to determine certification status. It outputs a formatted message
40-
// indicating whether the image is certified or not, using color helpers
41-
// for success (green) or failure (red). If validation fails or an error
42-
// occurs during certification check, it returns an error.
4333
func checkImageCertStatus(cmd *cobra.Command, _ []string) error {
4434
imageName, _ := cmd.Flags().GetString("name")
4535
imageRegistry, _ := cmd.Flags().GetString("registry")
@@ -74,11 +64,6 @@ func checkImageCertStatus(cmd *cobra.Command, _ []string) error {
7464
return nil
7565
}
7666

77-
// NewCommand creates and configures a cobra command for checking image certificate status.
78-
//
79-
// It returns a pointer to a cobra.Command that includes persistent flags for image,
80-
// registry, namespace, and other options. The function sets up flag requirements
81-
// and mutual exclusivity rules before returning the configured command.
8267
func NewCommand() *cobra.Command {
8368
checkImageCertStatusCmd.PersistentFlags().String("name", "", "name of the image to verify")
8469
checkImageCertStatusCmd.PersistentFlags().String("registry", "", "registry where the image is stored")

cmd/certsuite/check/results/results.go

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

29-
// TestCaseList holds the names of test cases grouped by result status.
30-
//
31-
// It contains three slices of strings: Fail, Pass, and Skip,
32-
// each holding the identifiers of test cases that ended with
33-
// the corresponding outcome during a certsuite run.
3429
type TestCaseList struct {
3530
Pass []string `yaml:"pass"`
3631
Fail []string `yaml:"fail"`
3732
Skip []string `yaml:"skip"`
3833
}
3934

40-
// TestResults represents the collection of test case outcomes.
41-
//
42-
// It embeds a TestCaseList to provide access to individual test cases and their
43-
// execution status. The struct is used to aggregate results from multiple
44-
// test runs within the certsuite command-line tool, enabling reporting,
45-
// filtering, and further analysis of test outcomes.
4635
type TestResults struct {
4736
TestCaseList `yaml:"testCases"`
4837
}
@@ -53,12 +42,6 @@ var checkResultsCmd = &cobra.Command{
5342
RunE: checkResults,
5443
}
5544

56-
// checkResults compares test results with expected values and writes a report.
57-
//
58-
// It retrieves command flags, loads the stored test results from the database,
59-
// compares them against expected outcomes, and optionally generates a template
60-
// file. Mismatches are printed to stdout and cause the program to exit with
61-
// an error status. The function returns an error if any operation fails.
6245
func checkResults(cmd *cobra.Command, _ []string) error {
6346
templateFileName, _ := cmd.Flags().GetString("template")
6447
generateTemplate, _ := cmd.Flags().GetBool("generate-template")
@@ -107,14 +90,6 @@ func checkResults(cmd *cobra.Command, _ []string) error {
10790
return nil
10891
}
10992

110-
// getTestResultsDB reads a test results file and returns a map of test identifiers to their outcome.
111-
//
112-
// getTestResultsDB parses the specified file path, expecting lines formatted as
113-
// "testID: result". It returns a map where each key is the test identifier and
114-
// the value is one of the predefined result constants (pass, fail, skip, miss).
115-
// If the file cannot be opened or any parsing error occurs, it returns an
116-
// error describing the problem. The function does not modify the input file
117-
// and closes it before returning.
11893
func getTestResultsDB(logFileName string) (map[string]string, error) {
11994
resultsDB := make(map[string]string)
12095

@@ -149,12 +124,6 @@ func getTestResultsDB(logFileName string) (map[string]string, error) {
149124
return resultsDB, nil
150125
}
151126

152-
// getExpectedTestResults reads a JSON file containing expected test results and returns them as a map.
153-
//
154-
// It takes the path to a template file, opens and parses its contents into a
155-
// map where keys are test identifiers and values are expected result strings.
156-
// The function returns the populated map or an error if the file cannot be read,
157-
// the data cannot be unmarshaled, or any other issue occurs.
158127
func getExpectedTestResults(templateFileName string) (map[string]string, error) {
159128
templateFile, err := os.ReadFile(templateFileName)
160129
if err != nil {
@@ -181,12 +150,6 @@ func getExpectedTestResults(templateFileName string) (map[string]string, error)
181150
return expectedTestResults, nil
182151
}
183152

184-
// printTestResultsMismatch reports mismatched test results between two sets.
185-
//
186-
// It takes three arguments: a slice of test names, a map of expected results,
187-
// and a map of actual results. The function compares each test's expected
188-
// outcome with the actual outcome, printing a formatted table that shows
189-
// which tests passed, failed, were skipped, or missed. No value is returned.
190153
func printTestResultsMismatch(mismatchedTestCases []string, actualResults, expectedResults map[string]string) {
191154
fmt.Printf("\n")
192155
fmt.Println(strings.Repeat("-", 96)) //nolint:mnd // table line
@@ -206,12 +169,6 @@ func printTestResultsMismatch(mismatchedTestCases []string, actualResults, expec
206169
}
207170
}
208171

209-
// generateTemplateFile writes a JSON file from the provided map of strings.
210-
//
211-
// It creates a temporary buffer, encodes the map as pretty‑printed JSON,
212-
// and writes the result to a file named by TestResultsTemplateFileName
213-
// with permissions specified by TestResultsTemplateFilePermissions.
214-
// If any step fails, it returns an error describing the problem.
215172
func generateTemplateFile(resultsDB map[string]string) error {
216173
var resultsTemplate TestResults
217174
for testCase, result := range resultsDB {
@@ -244,14 +201,6 @@ func generateTemplateFile(resultsDB map[string]string) error {
244201
return nil
245202
}
246203

247-
// NewCommand creates the command used to run checks on a set of test results.
248-
//
249-
// It returns a *cobra.Command configured with persistent flags that control
250-
// output formatting, filtering, and other behavior. The command exposes flags
251-
// for specifying output files, choosing which result states to display,
252-
// enabling or disabling verbose output, and selecting whether to mark
253-
// mutually exclusive options. The returned command is intended to be added
254-
// to the main application’s root command hierarchy.
255204
func NewCommand() *cobra.Command {
256205
checkResultsCmd.PersistentFlags().String("template", "expected_results.yaml", "reference YAML template with the expected results")
257206
checkResultsCmd.PersistentFlags().String("log-file", "certsuite.log", "log file of the Certsuite execution")

cmd/certsuite/claim/claim.go

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

16-
// NewCommand creates the root command for the claim subcommand.
17-
//
18-
// It constructs a new cobra.Command instance, configures it with
19-
// usage information and registers any child commands by calling AddCommand.
20-
// The returned *cobra.Command is ready to be added to the main application
21-
// command tree.
2216
func NewCommand() *cobra.Command {
2317
claimCommand.AddCommand(compare.NewCommand())
2418
claimCommand.AddCommand(show.NewCommand())

cmd/certsuite/claim/compare/compare.go

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

89-
// NewCommand creates a cobra command for comparing two claim files.
90-
//
91-
// It defines flags for the first and second claim file paths, marks them as required,
92-
// and sets up the command to execute the comparison logic when run.
93-
// The function returns a fully configured *cobra.Command ready to be added to a root command.
9489
func NewCommand() *cobra.Command {
9590
claimCompareFiles.Flags().StringVarP(
9691
&Claim1FilePathFlag, "claim1", "1", "",
@@ -114,15 +109,6 @@ func NewCommand() *cobra.Command {
114109
return claimCompareFiles
115110
}
116111

117-
// claimCompare compares two claim files and reports differences.
118-
//
119-
// It accepts a cobra.Command pointer and a slice of string arguments, typically
120-
// the command context and any positional parameters. The function retrieves the
121-
// file paths from the global flags Claim1FilePathFlag and Claim2FilePathFlag,
122-
// invokes claimCompareFilesfunc to perform the comparison, and handles errors.
123-
// On failure it calls Fatal to terminate the program with an error message.
124-
// The returned error is nil if the comparison succeeds or a non‑nil value
125-
// indicating a problem during execution.
126112
func claimCompare(_ *cobra.Command, _ []string) error {
127113
err := claimCompareFilesfunc(Claim1FilePathFlag, Claim2FilePathFlag)
128114
if err != nil {
@@ -131,14 +117,6 @@ func claimCompare(_ *cobra.Command, _ []string) error {
131117
return nil
132118
}
133119

134-
// claimCompareFilesfunc compares two claim files and reports differences.
135-
//
136-
// It reads the file at path1, unmarshals it into a Claim object,
137-
// then reads the file at path2 and unmarshals that as well.
138-
// The function uses Compare to compute a diff report between the
139-
// two claims. If any read or unmarshal error occurs, an error is
140-
// returned immediately. On success, the diff report is printed to
141-
// standard output and nil is returned.
142120
func claimCompareFilesfunc(claim1, claim2 string) error {
143121
// readfiles
144122
claimdata1, err := os.ReadFile(claim1)
@@ -183,12 +161,6 @@ func claimCompareFilesfunc(claim1, claim2 string) error {
183161
return nil
184162
}
185163

186-
// unmarshalClaimFile reads a claim file from bytes and returns the parsed schema.
187-
//
188-
// It accepts a byte slice containing the JSON representation of a claim
189-
// document, unmarshals it into a claim.Schema structure using the standard
190-
// encoding/json package, and returns that schema along with any error
191-
// encountered during decoding. If successful, the returned error is nil.
192164
func unmarshalClaimFile(claimdata []byte) (claim.Schema, error) {
193165
var claimDataResult claim.Schema
194166
err := json.Unmarshal(claimdata, &claimDataResult)

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

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

10-
// AbnormalEventsCount holds the number of abnormal events for two claims.
11-
//
12-
// It contains integer fields Claim1 and Claim2 that represent the count of
13-
// abnormal events detected for each respective claim. The String method
14-
// returns a formatted string summarizing these counts.
1510
type AbnormalEventsCount struct {
1611
Claim1 int `json:"claim1"`
1712
Claim2 int `json:"claim2"`
1813
}
1914

20-
// String returns a human‑readable representation of the abnormal events count.
21-
//
22-
// It formats the internal counters into a single string, allowing easy
23-
// printing or logging of the number of abnormal events recorded.
2415
func (c *AbnormalEventsCount) String() string {
2516
const (
2617
rowHeaderFmt = "%-12s%-s\n"
@@ -34,23 +25,11 @@ func (c *AbnormalEventsCount) String() string {
3425
return str
3526
}
3627

37-
// DiffReport represents the result of comparing two configurations.
38-
//
39-
// It contains the number of abnormal events detected during the comparison
40-
// in the AbnormalEvents field, and a pointer to a diff.Diffs value that
41-
// describes the differences between the two configuration objects.
42-
// The String method returns a human‑readable summary of the report.
4328
type DiffReport struct {
4429
Config *diff.Diffs `json:"CertSuiteConfig"`
4530
AbnormalEvents AbnormalEventsCount `json:"abnormalEventsCount"`
4631
}
4732

48-
// String returns a human‑readable representation of the DiffReport.
49-
//
50-
// It formats the differences between two configuration sets into a single
51-
// string, suitable for printing or logging. The returned value is a plain
52-
// text description that lists added, removed, and changed items in a
53-
// readable layout.
5433
func (d *DiffReport) String() string {
5534
str := "CONFIGURATIONS\n"
5635
str += "--------------\n\n"
@@ -63,11 +42,6 @@ func (d *DiffReport) String() string {
6342
return str
6443
}
6544

66-
// GetDiffReport produces a diff report between two configuration sets.
67-
//
68-
// It compares the first configuration set with the second and returns a DiffReport
69-
// that summarizes differences, additions, and removals. The returned value contains
70-
// details of what changed and is nil if an error occurs during comparison.
7145
func GetDiffReport(claim1Configurations, claim2Configurations *claim.Configurations) *DiffReport {
7246
return &DiffReport{
7347
Config: diff.Compare("Cert Suite Configuration", claim1Configurations.Config, claim2Configurations.Config, nil),

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

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

11-
// Diffs holds the differences between two JSON objects that have been unmarshalled into interface{} values.
12-
//
13-
// It records three slices: Fields contains field-by-field differences with their values from each object; FieldsInClaim1Only lists fields present only in the first object; and FieldsInClaim2Only lists fields present only in the second. The Name field can be used to label the comparison when rendering or logging.
11+
// Diffs holds the differences between two interface{} objects that have
12+
// been obtained by unmarshalling JSON strings.
1413
type Diffs struct {
1514
// Name of the json object whose diffs are stored here.
1615
// It will be used when serializing the data in table format.
@@ -22,24 +21,32 @@ type Diffs struct {
2221
FieldsInClaim2Only []string
2322
}
2423

25-
// FieldDiff holds information about a field that differs between two claim files.
26-
//
27-
// It stores the path of the differing field and the corresponding values from each claim file.
24+
// FieldDIff holds the field path and the values from both claim files
25+
// that have been found to be different.
2826
type FieldDiff struct {
2927
FieldPath string `json:"field"`
3028
Claim1Value interface{} `json:"claim1Value"`
3129
Claim2Value interface{} `json:"claim2Value"`
3230
}
3331

34-
// String returns a formatted table showing the differences between two claims.
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+
// ...
3546
//
36-
// It generates a multi-line string that lists fields present in both claims with
37-
// their differing values, as well as fields unique to each claim.
38-
// The output is organized into sections titled "<name>: Differences",
39-
// "<name>: Only in CLAIM 1", and "<name>: Only in CLAIM 2", where <name> is the
40-
// value of d.Name. Columns are padded to accommodate the longest field path
41-
// and value, ensuring a readable table layout. This method implements the
42-
// Stringer interface for Diffs.
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.
4350
func (d *Diffs) String() string {
4451
const (
4552
noDiffs = "<none>"
@@ -103,13 +110,13 @@ func (d *Diffs) String() string {
103110
return str
104111
}
105112

106-
// Compare compares two interface{} objects obtained through json.Unmarshal() and returns a pointer to a Diffs object.
107-
//
108-
// It accepts a JSON path string, the left and right interface values to compare,
109-
// and an optional slice of filter strings that restrict traversal to specific subtrees.
110-
// Only nodes whose paths match any filter are examined; all other parts of the trees are ignored.
111-
// The function walks both structures in parallel, records differences into a Diffs instance,
112-
// and returns a pointer to that instance for further inspection.
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.
113120
func Compare(objectName string, claim1Object, claim2Object interface{}, filters []string) *Diffs {
114121
objectsDiffs := Diffs{Name: objectName}
115122

@@ -156,26 +163,13 @@ func Compare(objectName string, claim1Object, claim2Object interface{}, filters
156163
return &objectsDiffs
157164
}
158165

159-
// field represents a leaf node in a nested structure, storing its path and value.
160-
//
161-
// It is used internally by the traversal logic to capture each terminal field
162-
// encountered during a recursive walk of an arbitrary data structure.
163-
// The Path field holds the dot‑separated string that identifies the location
164-
// of the value within the original object. Value contains the actual leaf
165-
// value, which may be any Go type.
166166
type field struct {
167167
Path string
168168
Value interface{}
169169
}
170170

171-
// traverse recursively walks a node, returning each leaf field's path and value.
172-
//
173-
// It accepts an interface{} representing the current node, a string prefix
174-
// for building the field path, and a slice of strings that holds the
175-
// accumulated paths so far. The function returns a slice of field structs,
176-
// each containing a full path to a leaf node and its corresponding value.
177-
// This helper is used to flatten nested structures into a list of
178-
// key/value pairs for comparison purposes.
171+
// Helper function that traverses recursively a node to return a list
172+
// of each field (leaf) path and its value.
179173
func traverse(node interface{}, path string, filters []string) []field {
180174
if node == nil {
181175
return nil

0 commit comments

Comments
 (0)