-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* torqueue init * support torce cluster create * support centos and ubuntu base image for torque test case * rename mod name * modify build configuration * fix unittest bugs * modify code generator * rm sdk pkg for test go * fix update-codegen bug * add golangci-lint * fix pbs bug * polymerization pbspro cmd * polymerization slurm cmd * add unittest
- Loading branch information
Showing
52 changed files
with
1,817 additions
and
279 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
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 |
---|---|---|
@@ -1 +1,69 @@ | ||
package v1alpha1_test | ||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestSetDefaults_KubeCluster(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
|
||
t.Run("test empty kube cluster", func(t *testing.T) { | ||
var replica2 int32 = 2 | ||
kclusetr := &KubeCluster{Spec: ClusterSpec{ | ||
ClusterType: "", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{ | ||
"replica1": {}, "replica2": {Replicas: &replica2}}, | ||
MainContainer: "", | ||
RunPolicy: RunPolicy{}, | ||
}} | ||
SetDefaults_KubeCluster(kclusetr) | ||
|
||
gomega.Expect(kclusetr.Spec.MainContainer).To(gomega.Equal(ClusterDefaultContainerName)) | ||
gomega.Expect(*kclusetr.Spec.RunPolicy.CleanKubeNodePolicy).To(gomega.Equal(CleanKubeNodePolicyAll)) | ||
|
||
gomega.Expect(*kclusetr.Spec.ClusterReplicaSpec["replica1"].Replicas).To(gomega.Equal(int32(1))) | ||
gomega.Expect(*kclusetr.Spec.ClusterReplicaSpec["replica2"].Replicas).To(gomega.Equal(int32(2))) | ||
}) | ||
} | ||
|
||
func TestSetDefaults_KubeClusterList(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
|
||
var replica2 int32 = 2 | ||
testCount := 10 | ||
kclusterList := &KubeClusterList{Items: make([]KubeCluster, 0)} | ||
for i := 0; i < testCount; i++ { | ||
kclusetr := KubeCluster{Spec: ClusterSpec{ | ||
ClusterType: "", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{ | ||
"replica1": {}, "replica2": {Replicas: &replica2}}, | ||
MainContainer: "", | ||
RunPolicy: RunPolicy{}, | ||
}} | ||
kclusterList.Items = append(kclusterList.Items, kclusetr) | ||
} | ||
SetDefaults_KubeClusterList(kclusterList) | ||
for i := 0; i < testCount; i++ { | ||
t.Run("test empty kube cluster", func(t *testing.T) { | ||
kclusetr := kclusterList.Items[i] | ||
gomega.Expect(kclusetr.Spec.MainContainer).To(gomega.Equal(ClusterDefaultContainerName)) | ||
gomega.Expect(*kclusetr.Spec.RunPolicy.CleanKubeNodePolicy).To(gomega.Equal(CleanKubeNodePolicyAll)) | ||
|
||
gomega.Expect(*kclusetr.Spec.ClusterReplicaSpec["replica1"].Replicas).To(gomega.Equal(int32(1))) | ||
gomega.Expect(*kclusetr.Spec.ClusterReplicaSpec["replica2"].Replicas).To(gomega.Equal(int32(2))) | ||
}) | ||
} | ||
} | ||
|
||
func Test_setDefaultReplicas(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
|
||
t.Run("test replicaSpec not set replica", func(t *testing.T) { | ||
replicaSpec := &ReplicaSpec{} | ||
setDefaultReplicas(replicaSpec, 1) | ||
gomega.Expect(*replicaSpec.Replicas).To(gomega.Equal(int32(1))) | ||
}) | ||
} |
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
175 changes: 175 additions & 0 deletions
175
apis/kubecluster.org/v1alpha1/cluster_validation_test.go
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,175 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/pointer" | ||
"testing" | ||
) | ||
|
||
func TestValidateV1alphaCluster(t *testing.T) { | ||
validClusterSpec := ClusterSpec{ | ||
ClusterType: "test", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{"test": { | ||
Replicas: pointer.Int32(1), | ||
Template: ReplicaTemplate{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Name: ClusterDefaultContainerName, | ||
Image: "centos", | ||
}}, | ||
}, | ||
}, | ||
}}, | ||
} | ||
type args struct { | ||
cluster *KubeCluster | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
"valid kubeCluster", | ||
args{ | ||
&KubeCluster{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "test"}, | ||
Spec: validClusterSpec, | ||
}, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"kubeCluster name does not meet DNS1035", | ||
args{ | ||
&KubeCluster{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "0-test"}, | ||
Spec: validClusterSpec, | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"cluster type is empty", | ||
args{ | ||
&KubeCluster{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "test"}, | ||
Spec: ClusterSpec{ClusterType: ""}, | ||
}, | ||
}, | ||
true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := ValidateV1alphaCluster(tt.args.cluster); (err != nil) != tt.wantErr { | ||
t.Errorf("ValidateV1alphaCluster() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
Test_validateV1alphaClusterSpecs(t) | ||
} | ||
|
||
func Test_validateV1alphaClusterSpecs(t *testing.T) { | ||
type args struct { | ||
spec ClusterSpec | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
"replica specs are empty", | ||
args{ | ||
ClusterSpec{ | ||
ClusterType: "test", | ||
ClusterReplicaSpec: make(map[ReplicaType]*ReplicaSpec), | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"no containers", | ||
args{ | ||
ClusterSpec{ | ||
ClusterType: "test", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{"test": { | ||
Replicas: pointer.Int32(1), | ||
Template: ReplicaTemplate{ | ||
Spec: corev1.PodSpec{}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"main container name doesn't present", | ||
args{ | ||
ClusterSpec{ | ||
ClusterType: "test", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{"test": { | ||
Replicas: pointer.Int32(1), | ||
Template: ReplicaTemplate{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Image: "centos", | ||
}}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"main container name not consistent", | ||
args{ | ||
ClusterSpec{ | ||
ClusterType: "test", | ||
MainContainer: "testmain", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{"test": { | ||
Replicas: pointer.Int32(1), | ||
Template: ReplicaTemplate{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Name: ClusterDefaultContainerName, | ||
Image: "centos", | ||
}}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
true, | ||
}, | ||
{ | ||
"image is empty", | ||
args{ | ||
ClusterSpec{ | ||
ClusterType: "test", | ||
ClusterReplicaSpec: map[ReplicaType]*ReplicaSpec{"test": { | ||
Replicas: pointer.Int32(1), | ||
Template: ReplicaTemplate{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{{ | ||
Name: ClusterDefaultContainerName, | ||
}}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
}, | ||
true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validateV1alphaClusterSpecs(tt.args.spec); (err != nil) != tt.wantErr { | ||
t.Errorf("validateV1alphaClusterSpecs() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.