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:
parent
57ca03e134
commit
b719682e7c
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue