add s2irun controller test

Signed-off-by: runzexia <runzexia@yunify.com>
This commit is contained in:
runzexia
2020-03-19 10:35:15 +08:00
parent 6a7bf0a86f
commit 71898e59dd
5 changed files with 319 additions and 19 deletions

View File

@@ -43,7 +43,7 @@ type S2iBinaryController struct {
func NewController(client clientset.Interface,
devopsclientset devopsclient.Interface,
s2ibinInformer devopsinformers.S2iBinaryInformer,
s3Client s3.Interface) *S2iBinaryController {
s3Client s3.Interface) *S2iBinaryController {
broadcaster := record.NewBroadcaster()
broadcaster.StartLogging(func(format string, args ...interface{}) {
@@ -59,7 +59,7 @@ func NewController(client clientset.Interface,
s2iBinaryLister: s2ibinInformer.Lister(),
s2iBinarySynced: s2ibinInformer.Informer().HasSynced,
workerLoopPeriod: time.Second,
s3Client: s3Client,
s3Client: s3Client,
}
v.eventBroadcaster = broadcaster

View File

@@ -33,9 +33,9 @@ type fixture struct {
s2ibinaryLister []*s2i.S2iBinary
actions []core.Action
// Objects from here preloaded into NewSimpleFake.
objects []runtime.Object
objects []runtime.Object
// Objects from here preloaded into s3
initS3Objects []*fakeS3.Object
initS3Objects []*fakeS3.Object
expectS3Objects []*fakeS3.Object
}
@@ -53,9 +53,7 @@ func newS2iBinary(name string, spec s2i.S2iBinarySpec) *s2i.S2iBinary {
Name: name,
Namespace: metav1.NamespaceDefault,
},
Spec: s2i.S2iBinarySpec{
},
Spec: s2i.S2iBinarySpec{},
}
}
func newDeletingS2iBinary(name string) *s2i.S2iBinary {
@@ -63,14 +61,11 @@ func newDeletingS2iBinary(name string) *s2i.S2iBinary {
return &s2i.S2iBinary{
TypeMeta: metav1.TypeMeta{APIVersion: s2i.SchemeGroupVersion.String()},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: metav1.NamespaceDefault,
Finalizers:[]string{s2i.S2iBinaryFinalizerName},
Name: name,
Namespace: metav1.NamespaceDefault,
Finalizers: []string{s2i.S2iBinaryFinalizerName},
DeletionTimestamp: &deleteTime,
},
Spec: s2i.S2iBinarySpec{
},
}
}
@@ -130,7 +125,7 @@ func (f *fixture) runController(s2iBinaryName string, startInformers bool, expec
if len(f.actions) > len(actions) {
f.t.Errorf("%d additional expected actions:%+v", len(f.actions)-len(actions), f.actions[len(actions):])
}
if len(s3I.Storage) != len(f.expectS3Objects){
if len(s3I.Storage) != len(f.expectS3Objects) {
f.t.Errorf(" unexpected objects: %v", s3I.Storage)
}
}
@@ -234,10 +229,9 @@ func TestDeleteS3Object(t *testing.T) {
f.objects = append(f.objects, s2iBinary)
f.initS3Objects = []*fakeS3.Object{&fakeS3.Object{
Key: "default-test",
},}
}}
f.expectS3Objects = []*fakeS3.Object{}
f.expectUpdateS2iBinaryAction(s2iBinary)
f.run(getKey(s2iBinary, t))
}