From 3d2913efd021733dafafc1e788456512a9483012 Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Thu, 14 Mar 2024 11:24:57 +0530 Subject: [PATCH] test: Adding fuzz test for getEnvFromMap in builders.go (#213) --- pkg/utils/builders_fuzz_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pkg/utils/builders_fuzz_test.go diff --git a/pkg/utils/builders_fuzz_test.go b/pkg/utils/builders_fuzz_test.go new file mode 100644 index 0000000..705266a --- /dev/null +++ b/pkg/utils/builders_fuzz_test.go @@ -0,0 +1,24 @@ +package utils + +import ( + fuzz "github.com/AdaLogics/go-fuzz-headers" + "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + "testing" +) + +func FuzzGetEnvFromMap(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + fuzzConsumer := fuzz.NewConsumer(data) + targetStruct := &struct { + m map[string]corev1.EnvVar + }{} + err := fuzzConsumer.GenerateStruct(targetStruct) + if err != nil { + return + } + envs := getEnvFromMap(targetStruct.m) + var envCount = len(envs) + require.Equal(t, envCount, len(targetStruct.m)+1) + }) +}