From caf5da1fc7db278bce0efbab1339ab7768731210 Mon Sep 17 00:00:00 2001 From: 221220047 <221220047@smail.nju.edu.cn> Date: Sun, 9 Mar 2025 16:00:18 +0800 Subject: [PATCH] Add Notation to TestAlluxioEngine_allocateSinglePort in pkg\ddc\alluxio\transform_test.go Signed-off-by: 221220047 <221220047@smail.nju.edu.cn> --- pkg/ddc/alluxio/transform_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/ddc/alluxio/transform_test.go b/pkg/ddc/alluxio/transform_test.go index 4f27550d119..fd6480fab28 100755 --- a/pkg/ddc/alluxio/transform_test.go +++ b/pkg/ddc/alluxio/transform_test.go @@ -584,7 +584,22 @@ func TestGetMediumTypeFromVolumeSource(t *testing.T) { } } +// TestAlluxioEngine_allocateSinglePort is a unit test function that tests +// the `allocateSinglePort` method of the `AlluxioEngine` struct. +// The function verifies the behavior of port allocation for Alluxio master +// and worker components under different scenarios, +// including when properties are set, unset, or when runtime specifications +// are provided. +// +// Parameters: +// - t: A testing.T object provided by the Go testing framework, used to +// manage test state and support formatted test logs. +// +// Returns: +// - None. The function is a test function and does not return any value. +// It reports test failures using the `t.Errorf` method. func TestAlluxioEngine_allocateSinglePort(t *testing.T) { + // Define the fields required for the AlluxioEngine struct. type fields struct { runtime *datav1alpha1.AlluxioRuntime name string @@ -596,11 +611,13 @@ func TestAlluxioEngine_allocateSinglePort(t *testing.T) { initImage string MetadataSyncDoneCh chan base.MetadataSyncResult } + // Define the arguments required for the test cases. type args struct { allocatedPorts []int alluxioValue *Alluxio } + // Define a slice of test cases, each with a name, fields, arguments, and expected results. tests := []struct { name string fields fields @@ -667,8 +684,10 @@ func TestAlluxioEngine_allocateSinglePort(t *testing.T) { wantPorts: []int{20005}, }, } + // Iterate over each test case and run the test. for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + // Initialize the AlluxioEngine with the fields from the test case. e := &AlluxioEngine{ runtime: tt.fields.runtime, name: tt.fields.name, @@ -681,6 +700,7 @@ func TestAlluxioEngine_allocateSinglePort(t *testing.T) { MetadataSyncDoneCh: tt.fields.MetadataSyncDoneCh, } + // Initialize index and preIndex to track the position in the allocated ports slice. index := 0 preIndex := 0