From 3e988afc09c914e1385e21f949e073d42f979237 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Thu, 19 May 2022 21:34:23 +0900 Subject: [PATCH] test: add fuzzing to the test suite (#1463) As a part of #1298, we add fuzzing based on Go test's fuzzing support to the test suite --- Makefile | 1 + controllers/schedule_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Makefile b/Makefile index 5046e2fb..3e6bd47c 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,7 @@ GO_TEST_ARGS ?= -short # Run tests test: generate fmt vet manifests go test $(GO_TEST_ARGS) ./... -coverprofile cover.out + go test -fuzz=Fuzz -fuzztime=10s -run=Fuzz* ./controllers test-with-deps: kube-apiserver etcd kubectl # See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest#pkg-constants diff --git a/controllers/schedule_test.go b/controllers/schedule_test.go index 9190bf67..79b03b85 100644 --- a/controllers/schedule_test.go +++ b/controllers/schedule_test.go @@ -605,3 +605,13 @@ func parseAndMatchRecurringPeriod(now time.Time, start, end, frequency, until st return MatchSchedule(now, startTime, endTime, RecurrenceRule{Frequency: frequency, UntilTime: untilTime}) } + +func FuzzMatchSchedule(f *testing.F) { + start := time.Now() + end := time.Now() + now := time.Now() + f.Fuzz(func(t *testing.T, freq string) { + // Verify that it never panics + _, _, _ = MatchSchedule(now, start, end, RecurrenceRule{Frequency: freq}) + }) +}