Skip to content
Closed
Show file tree
Hide file tree
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
170 changes: 71 additions & 99 deletions pkg/application/inject/fuse/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,114 +17,86 @@ limitations under the License.
package fuse

import (
"testing"

"github.com/fluid-cloudnative/fluid/pkg/utils/applications/pod"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)

var _ = Describe("findInjectedSidecars", func() {
Context("when there are no injected sidecars", func() {
It("should return an empty slice", func() {
pod1 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test",
},
{
Name: "test2",
},
},
},
}
podObjs, err := pod.NewApplication(pod1).GetPodSpecs()
Expect(err).NotTo(HaveOccurred())
const testFuseSidecarName0 = "fluid-fuse-0"

injectedSidecars, err := findInjectedSidecars(podObjs[0])
Expect(err).NotTo(HaveOccurred())
Expect(injectedSidecars).To(BeEmpty())
})
})
func TestFindInjectedSidecars_NoSidecars(t *testing.T) {
pod1 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{Name: "test"},
{Name: "test2"},
},
},
}
podObjs, err := pod.NewApplication(pod1).GetPodSpecs()
assert.NoError(t, err)

Context("when there is one injected sidecar", func() {
It("should return the injected sidecar", func() {
pod2 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "fluid-fuse-0",
},
{
Name: "test",
},
},
},
}
podObjs, err := pod.NewApplication(pod2).GetPodSpecs()
Expect(err).NotTo(HaveOccurred())
injectedSidecars, err := findInjectedSidecars(podObjs[0])
assert.NoError(t, err)
assert.Empty(t, injectedSidecars)
}

injectedSidecars, err := findInjectedSidecars(podObjs[0])
Expect(err).NotTo(HaveOccurred())
Expect(injectedSidecars).To(HaveLen(1))
Expect(injectedSidecars[0].Name).To(Equal("fluid-fuse-0"))
})
})
func TestFindInjectedSidecars_OneSidecar(t *testing.T) {
pod2 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{Name: testFuseSidecarName0},
{Name: "test"},
},
},
}
podObjs, err := pod.NewApplication(pod2).GetPodSpecs()
assert.NoError(t, err)

Context("when there are multiple injected sidecars", func() {
It("should return all injected sidecars", func() {
pod3 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "fluid-fuse-0",
},
{
Name: "test",
},
{
Name: "fluid-fuse-1",
},
{
Name: "fluid-fuse-dataset-xyz",
},
},
},
}
podObjs, err := pod.NewApplication(pod3).GetPodSpecs()
Expect(err).NotTo(HaveOccurred())
injectedSidecars, err := findInjectedSidecars(podObjs[0])
assert.NoError(t, err)
assert.Len(t, injectedSidecars, 1)
assert.Equal(t, testFuseSidecarName0, injectedSidecars[0].Name)
}

injectedSidecars, err := findInjectedSidecars(podObjs[0])
Expect(err).NotTo(HaveOccurred())
Expect(injectedSidecars).To(HaveLen(3))
Expect(injectedSidecars[0].Name).To(Equal("fluid-fuse-0"))
Expect(injectedSidecars[1].Name).To(Equal("fluid-fuse-1"))
Expect(injectedSidecars[2].Name).To(Equal("fluid-fuse-dataset-xyz"))
})
})
func TestFindInjectedSidecars_MultipleSidecars(t *testing.T) {
pod3 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{Name: testFuseSidecarName0},
{Name: "test"},
{Name: "fluid-fuse-1"},
{Name: "fluid-fuse-dataset-xyz"},
},
},
}
podObjs, err := pod.NewApplication(pod3).GetPodSpecs()
assert.NoError(t, err)

Context("when container name contains but doesn't start with fluid-fuse prefix", func() {
It("should only return containers that start with the prefix", func() {
pod4 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test-fluid-fuse",
},
{
Name: "fluid-fuse-0",
},
},
},
}
podObjs, err := pod.NewApplication(pod4).GetPodSpecs()
Expect(err).NotTo(HaveOccurred())
injectedSidecars, err := findInjectedSidecars(podObjs[0])
assert.NoError(t, err)
assert.Len(t, injectedSidecars, 3)
assert.Equal(t, testFuseSidecarName0, injectedSidecars[0].Name)
assert.Equal(t, "fluid-fuse-1", injectedSidecars[1].Name)
assert.Equal(t, "fluid-fuse-dataset-xyz", injectedSidecars[2].Name)
}

injectedSidecars, err := findInjectedSidecars(podObjs[0])
Expect(err).NotTo(HaveOccurred())
Expect(injectedSidecars).To(HaveLen(1))
Expect(injectedSidecars[0].Name).To(Equal("fluid-fuse-0"))
})
})
func TestFindInjectedSidecars_PrefixOnly(t *testing.T) {
pod4 := &corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{Name: "test-fluid-fuse"},
{Name: testFuseSidecarName0},
},
},
}
podObjs, err := pod.NewApplication(pod4).GetPodSpecs()
assert.NoError(t, err)

})
injectedSidecars, err := findInjectedSidecars(podObjs[0])
assert.NoError(t, err)
assert.Len(t, injectedSidecars, 1)
assert.Equal(t, testFuseSidecarName0, injectedSidecars[0].Name)
}
24 changes: 14 additions & 10 deletions pkg/application/inject/fuse/fuse_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package fuse_test
/*
Copyright 2026 The Fluid Authors.

import (
"testing"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
http://www.apache.org/licenses/LICENSE-2.0

func TestFuse(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Application Fuse Injection Suite")
}
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fuse
Loading
Loading