Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/ddc/alluxio/transform_ufs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ import (
v1 "k8s.io/api/core/v1"
)

// TestTransformDatasetToVolume is a unit test function that verifies the transformation of a Dataset into a UFSPath
// in the Alluxio runtime. It ensures that the Dataset's mount points are correctly converted into corresponding
// container and host paths.
//
// Parameters:
// - t: *testing.T, the Go testing framework's object used to manage the test execution and report failures.
//
// Return value:
// - None (this is a test function, and it does not return any values).
func TestTransformDatasetToVolume(t *testing.T) {
// Initialize UFSPath variables for expected results.
var ufsPath = UFSPath{}
ufsPath.Name = "test"
ufsPath.HostPath = "/mnt/test"
Expand All @@ -34,12 +44,14 @@ func TestTransformDatasetToVolume(t *testing.T) {
ufsPath1.HostPath = "/mnt/test"
ufsPath1.ContainerPath = "/underFSStorage"

// Define test cases with different Dataset configurations
var tests = []struct {
runtime *datav1alpha1.AlluxioRuntime
dataset *datav1alpha1.Dataset
value *Alluxio
expect UFSPath
}{
// Test case 1: Simple Mount configuration
{&datav1alpha1.AlluxioRuntime{}, &datav1alpha1.Dataset{
Spec: datav1alpha1.DatasetSpec{
Mounts: []datav1alpha1.Mount{{
Expand All @@ -48,6 +60,8 @@ func TestTransformDatasetToVolume(t *testing.T) {
}},
},
}, &Alluxio{}, ufsPath},

// Test case 2: Mount with a path specified
{&datav1alpha1.AlluxioRuntime{}, &datav1alpha1.Dataset{
Spec: datav1alpha1.DatasetSpec{
Mounts: []datav1alpha1.Mount{{
Expand All @@ -58,11 +72,17 @@ func TestTransformDatasetToVolume(t *testing.T) {
},
}, &Alluxio{}, ufsPath1},
}

// Iterate through all test cases and run the test.
for _, test := range tests {
// Create an instance of AlluxioEngine to call the function under test.
engine := &AlluxioEngine{}
// Call the function that we want to test.
engine.transformDatasetToVolume(test.runtime, test.dataset, test.value)
// Compare the actual result with the expected result.
if test.value.UFSPaths[0].HostPath != test.expect.HostPath ||
test.value.UFSPaths[0].ContainerPath != test.expect.ContainerPath {
// If the result doesn't match the expected values, report an error.
t.Errorf("expected %v, got %v", test.expect, test.value.UFSPaths[0])
}
}
Expand Down
Loading