diff --git a/pkg/printer/filter.go b/pkg/printer/filter.go index 49dfd0d2..aa858438 100644 --- a/pkg/printer/filter.go +++ b/pkg/printer/filter.go @@ -11,7 +11,7 @@ func FilterNonRelevantResults(results []judge.Result, tv *goversion.Version) ([] filtered := []judge.Result{} for i := range results { - if results[i].Since.LessThanOrEqual(tv) { + if results[i].Since == nil || results[i].Since.LessThanOrEqual(tv) { filtered = append(filtered, results[i]) } } diff --git a/pkg/printer/filter_test.go b/pkg/printer/filter_test.go index 77a12b7a..53a42e60 100644 --- a/pkg/printer/filter_test.go +++ b/pkg/printer/filter_test.go @@ -30,12 +30,21 @@ var testInput []judge.Result = []judge.Result{ ReplaceWith: "testReplaceWith2", Since: testVersion2, }, + { + Name: "testName3", + Kind: "testKind3", + Namespace: "testNamespace3", + ApiVersion: "v1", + RuleSet: "testRuleset3", + ReplaceWith: "testReplaceWith3", + Since: nil, + }, } func TestFilterNonRelevantResults(t *testing.T) { filterVersion, _ := goversion.NewVersion("2.0.0") - results, err := FilterNonRelevantResults(testInput, filterVersion) + results, err := FilterNonRelevantResults(testInput[0:2], filterVersion) if err != nil { t.Fatalf("failed to filter results: %s", err) } @@ -60,7 +69,20 @@ func TestFilterNonRelevantResultsEmpty(t *testing.T) { } } -func TestFilterNonRelevantResultsNilVersion(t *testing.T) { +func TestFilterNonRelevantResultsWithNilVersion(t *testing.T) { + filterVersion, _ := goversion.NewVersion("2.0.0") + + results, err := FilterNonRelevantResults(testInput[2:3], filterVersion) + if err != nil { + t.Fatalf("failed to filter results: %s", err) + } + + if len(results) != 1 { + t.Errorf("expected 1 results after filter, got %d intead", len(results)) + } +} + +func TestFilterNonRelevantResultsNilTargetVersion(t *testing.T) { var filterVersion *goversion.Version results, err := FilterNonRelevantResults(testInput, filterVersion) diff --git a/pkg/printer/json_test.go b/pkg/printer/json_test.go index 88e4f934..77ab2332 100644 --- a/pkg/printer/json_test.go +++ b/pkg/printer/json_test.go @@ -20,7 +20,7 @@ func TestJsonPopulateOutput(t *testing.T) { if err != nil { t.Fatal(err) } - if len(j) != 2 { + if len(j) != len(testInput) { t.Error("wrong number of results") } }