bugfix: CIFuzz fail due to timeout on FuzzReadExperimentFile (#4876)

* bugfix: CIFuzz fail due to timeout on FuzzReadExperimentFile
* Since we're testing for non-existent files in our unit tests, we'll skip the unnecessary tests.

Signed-off-by: Soyeon Park <sypark9646@gmail.com>

* bugfix: Delete the FuzzReadExperimentFile test case
* Deleting test cases due to timeouts

Signed-off-by: Soyeon Park <sypark9646@gmail.com>

* bugfix: CIFuzz fail due to timeout on FuzzProcessExperimentRunDelete

Signed-off-by: Soyeon Park <sypark9646@gmail.com>

---------

Signed-off-by: Soyeon Park <sypark9646@gmail.com>
Co-authored-by: Namkyu Park <53862866+namkyu1999@users.noreply.github.com>
This commit is contained in:
soyeon Park 2024-10-11 15:18:34 +09:00 committed by GitHub
parent 57ca03e134
commit b719682e7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 79 deletions

View File

@ -12,7 +12,6 @@ import (
fuzz "github.com/AdaLogics/go-fuzz-headers"
store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
"github.com/stretchr/testify/mock"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
@ -47,39 +46,6 @@ func NewMockServices() *MockServices {
}
}
func FuzzProcessExperimentRunDelete(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)
targetStruct := &struct {
Query bson.D
WorkflowRunID *string
ExperimentRun dbChaosExperimentRun.ChaosExperimentRun
Workflow dbChaosExperiment.ChaosExperimentRequest
Username string
StoreStateData *store.StateData
}{}
err := fuzzConsumer.GenerateStruct(targetStruct)
if err != nil {
return
}
mockServices := NewMockServices()
mockServices.MongodbOperator.On("Update", mock.Anything, mongodb.ChaosExperimentRunsCollection, mock.Anything, mock.Anything, mock.Anything).Return(&mongo.UpdateResult{}, nil).Once()
err = mockServices.ChaosExperimentRunService.ProcessExperimentRunDelete(
context.Background(),
targetStruct.Query,
targetStruct.WorkflowRunID,
targetStruct.ExperimentRun,
targetStruct.Workflow,
targetStruct.Username,
targetStruct.StoreStateData,
)
if err != nil {
t.Errorf("ProcessExperimentRunDelete() error = %v", err)
}
})
}
func FuzzProcessExperimentRunStop(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzConsumer := fuzz.NewConsumer(data)

View File

@ -41,51 +41,6 @@ func FuzzGetChartsPath(f *testing.F) {
})
}
func FuzzReadExperimentFile(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, filename string) {
fuzzConsumer := fuzz.NewConsumer(data)
// Create a temporary directory
tmpDir, err := os.MkdirTemp("", "*-fuzztest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpDir) // clean up
// Ensure the filename is valid and unique
safeFilename := filepath.Clean(filepath.Base(filename))
if isInvalidFilename(safeFilename) {
safeFilename = "test.yaml"
}
filePath := filepath.Join(tmpDir, safeFilename)
content := ChaosChart{}
err = fuzzConsumer.GenerateStruct(&content)
if err != nil {
return
}
jsonContent, _ := json.Marshal(content)
err = os.WriteFile(filePath, jsonContent, 0644)
if err != nil {
t.Fatal(err)
}
_, err = ReadExperimentFile(filePath)
if err != nil && !isInvalidYAML(jsonContent) {
t.Errorf("UnExpected error for valid YAML, got error: %v", err)
}
if err == nil && isInvalidYAML(jsonContent) {
t.Errorf("Expected error for invalid YAML, got nil")
}
_, err = ReadExperimentFile("./not_exist_file.yaml")
if err == nil {
t.Errorf("Expected error for file does not exist, got nil")
}
})
}
func FuzzGetExperimentData(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte, filename string) {
fuzzConsumer := fuzz.NewConsumer(data)