Skip to content
Open
Changes from 1 commit
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
75 changes: 75 additions & 0 deletions pkg/ddc/base/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

func TestGetPhysicalDatasetFromMounts(t *testing.T) {
Expand Down Expand Up @@ -266,3 +267,77 @@
})
}
}

func TestGetOwnerDatasetUIDFromRuntimeMeta(t *testing.T) {
uid := types.UID("dataset-uid-1")
tests := []struct {
name string
meta metav1.ObjectMeta
wantUID types.UID
expectErr bool
}{
{
name: "single dataset owner with same name",
meta: metav1.ObjectMeta{
Name: "sample-runtime",

Check failure on line 282 in pkg/ddc/base/dataset_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "sample-runtime" 6 times.

See more on https://sonarcloud.io/project/issues?id=fluid-cloudnative_fluid&issues=AZ1kNxAwlZMhgCvZu0_P&open=AZ1kNxAwlZMhgCvZu0_P&pullRequest=5769
OwnerReferences: []metav1.OwnerReference{
{
Kind: datav1alpha1.Datasetkind,
Name: "sample-runtime",
UID: uid,
},
},
},
wantUID: uid,
expectErr: false,
},
{
name: "dataset owner name mismatch",
meta: metav1.ObjectMeta{
Name: "sample-runtime",
OwnerReferences: []metav1.OwnerReference{
{
Kind: datav1alpha1.Datasetkind,
Name: "another-name",
UID: uid,
},
},
},
wantUID: "",
expectErr: true,
},
{
name: "multiple dataset owners",
meta: metav1.ObjectMeta{
Name: "sample-runtime",
OwnerReferences: []metav1.OwnerReference{
{
Kind: datav1alpha1.Datasetkind,
Name: "sample-runtime",
UID: uid,
},
{
Kind: datav1alpha1.Datasetkind,
Name: "sample-runtime",
UID: types.UID("dataset-uid-2"),
},
},
},
wantUID: "",
expectErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotUID, err := GetOwnerDatasetUIDFromRuntimeMeta(tt.meta)
if (err != nil) != tt.expectErr {
t.Errorf("GetOwnerDatasetUIDFromRuntimeMeta() error = %v, expectErr %v", err, tt.expectErr)
return
}
if gotUID != tt.wantUID {
t.Errorf("GetOwnerDatasetUIDFromRuntimeMeta() uid = %v, want %v", gotUID, tt.wantUID)
}
})
}
}
Loading