-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Phoeniix Zhao <[email protected]>
- Loading branch information
1 parent
e340e72
commit 43886a1
Showing
8 changed files
with
132 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestObjKey(t *testing.T) { | ||
xlineCluster := XlineCluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "xline", | ||
Namespace: "default", | ||
}, | ||
} | ||
expected_objkey := types.NamespacedName{Name: "xline", Namespace: "default"} | ||
assert.Equal(t, xlineCluster.ObjKey(), expected_objkey) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package reconciler | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
xapi "github.com/xline-kv/xline-operator/api/v1alpha1" | ||
) | ||
|
||
func TestStatusConvert(t *testing.T) { | ||
sucStage := clusterStageSucc(xapi.StageXlineService) | ||
failStage := clusterStageFail(xapi.StageXlineService, errors.New("failed to create service")) | ||
|
||
t.Run("Successful Status can covert to XlineClusterRecStatus properly", func(t *testing.T) { | ||
res := sucStage.AsXlineClusterRecStatus() | ||
assert.Equal(t, res.Stage, xapi.StageXlineService) | ||
assert.Equal(t, res.StageStatus, xapi.StageResultSucceeded) | ||
assert.True(t, res.LastMessage == "") | ||
}) | ||
|
||
t.Run("Failed Status can covert to XlineClusterRecStatus properly", func(t *testing.T) { | ||
res := failStage.AsXlineClusterRecStatus() | ||
assert.Equal(t, res.Stage, xapi.StageXlineService) | ||
assert.Equal(t, res.StageStatus, xapi.StageResultFailed) | ||
assert.Equal(t, res.LastMessage, "failed to create service") | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package transformer | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
xapi "github.com/xline-kv/xline-operator/api/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestXlineClusterFunc(t *testing.T) { | ||
test_image := "xline-img" | ||
test_image_version := "latest" | ||
xlineCluster := xapi.XlineCluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "xline", | ||
Namespace: "default", | ||
}, | ||
Spec: xapi.XlineClusterSpec{ | ||
Version: test_image_version, | ||
Image: &test_image, | ||
Replicas: 3, | ||
}, | ||
} | ||
|
||
t.Run("GetServiceKey should work properly", func(t *testing.T) { | ||
xcLookupKey := xlineCluster.ObjKey() | ||
svcObj := GetServiceKey(xcLookupKey) | ||
assert.Equal(t, svcObj.Namespace, "default") | ||
assert.Equal(t, svcObj.Name, "xline-svc") | ||
}) | ||
|
||
t.Run("GetStatefulSetKey should work properly", func(t *testing.T) { | ||
xcLookupKey := xlineCluster.ObjKey() | ||
stsObj := GetStatefulSetKey(xcLookupKey) | ||
assert.Equal(t, stsObj.Namespace, "default") | ||
assert.Equal(t, stsObj.Name, "xline-sts") | ||
}) | ||
|
||
t.Run("GetXlineImage should work properly", func(t *testing.T) { | ||
xline_image := GetXlineImage(&xlineCluster) | ||
assert.Equal(t, xline_image, "xline-img:latest") | ||
}) | ||
|
||
t.Run("GetMemberTopology should work properly", func(t *testing.T) { | ||
xcLookupKey := xlineCluster.ObjKey() | ||
stsRef := GetStatefulSetKey(xcLookupKey) | ||
svcName := GetServiceKey(xcLookupKey).Name | ||
topology := GetMemberTopology(stsRef, svcName, 3) | ||
topologyVec := strings.Split(topology, ",") | ||
assert.Equal(t, len(topologyVec), 3) | ||
for i := 0; i < 3; i++ { | ||
expectRes := fmt.Sprintf("xline-sts-%d=xline-sts-%d.xline-svc.default.svc.cluster.local:2379", i, i) | ||
assert.Equal(t, topologyVec[i], expectRes) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func TestK8sObjKeyStr(t *testing.T) { | ||
objkey := types.NamespacedName{Name: "xline", Namespace: "default"} | ||
assert.Equal(t, K8sObjKeyStr(objkey), "xline.default") | ||
} |