// TestGenerateDataLoadValueFile verifies that generateDataLoadValueFile creates
// a temporary values file for a DataLoad and returns the generated file path
// for both empty-target and explicit-target configurations.
func TestGenerateDataLoadValueFile(t *testing.T) {
// Prepare a dataset in the fake client so the dataload can resolve its target dataset.
datasetInputs := []datav1alpha1.Dataset{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataset",
Namespace: "fluid",
},
},
}
testObjs := []runtime.Object{}
for _, datasetInput := range datasetInputs {
testObjs = append(testObjs, datasetInput.DeepCopy())
}
client := fake.NewFakeClientWithScheme(testScheme, testObjs...)
context := cruntime.ReconcileRequestContext{
Client: client,
}
// Cover both branches where the dataload has no explicit targets and where it does.
dataLoadNoTarget := datav1alpha1.DataLoad{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataload",
Namespace: "fluid",
},
Spec: datav1alpha1.DataLoadSpec{
Dataset: datav1alpha1.TargetDataset{
Name: "test-dataset",
Namespace: "fluid",
},
},
}
dataLoadWithTarget := datav1alpha1.DataLoad{
ObjectMeta: metav1.ObjectMeta{
Name: "test-dataload",
Namespace: "fluid",
},
Spec: datav1alpha1.DataLoadSpec{
Dataset: datav1alpha1.TargetDataset{
Name: "test-dataset",
Namespace: "fluid",
},
Target: []datav1alpha1.TargetPath{
{
Path: "/test",
Replicas: 1,
},
},
},
}
testCases := []struct {
dataLoad datav1alpha1.DataLoad
expectFileName string
}{
{
dataLoad: dataLoadNoTarget,
expectFileName: filepath.Join(os.TempDir(), "fluid-test-dataload-loader-values.yaml"),
},
{
dataLoad: dataLoadWithTarget,
expectFileName: filepath.Join(os.TempDir(), "fluid-test-dataload-loader-values.yaml"),
},
}
// Generate the values file and assert that the returned temp file path matches the expected pattern.
for _, test := range testCases {
engine := AlluxioEngine{}
if fileName, err := engine.generateDataLoadValueFile(context, &test.dataLoad); !strings.Contains(fileName, test.expectFileName) {
t.Errorf("fail to generate the dataload value file: %v", err)
}
}
}
Which function do you want to add comments to?
TestGenerateDataLoadValueFile in fluid/pkg/ddc/alluxio/load_data_test.go.
What comments do you want to add?