Skip to content

Commit

Permalink
test: added rsa tests cases
Browse files Browse the repository at this point in the history
Each case tests for ECDSA keys is now also tested for RSA keys.

The tests were also accelerated by reducing the delay between checks
from 5s to 500m

Signed-off-by: Bruno Bressi <[email protected]>
  • Loading branch information
puffitos committed Sep 19, 2024
1 parent 9da39dd commit 8cd36fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
34 changes: 17 additions & 17 deletions test/framework/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (f *Framework) cleanupDeployments() {
f.t.Logf("All pods are deleted")
return
}
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
}
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (f *Framework) GetPods(d appsv1.Deployment) *corev1.PodList {
return nil
}

pods, err := f.k8s.CoreV1().Pods("test-cases").List(context.Background(), metav1.ListOptions{
pods, err := f.k8s.CoreV1().Pods(d.Namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", d.Name),
})
if err != nil {
Expand All @@ -159,7 +159,7 @@ func (f *Framework) CreateDeployment(d appsv1.Deployment) {
}

f.t.Logf("creating deployment %s", d.Name)
_, err := f.k8s.AppsV1().Deployments("test-cases").Create(context.Background(), &d, metav1.CreateOptions{})
_, err := f.k8s.AppsV1().Deployments(d.Namespace).Create(context.Background(), &d, metav1.CreateOptions{})
if err != nil {
f.err = err
return
Expand All @@ -168,18 +168,18 @@ func (f *Framework) CreateDeployment(d appsv1.Deployment) {
}

// CreateSecret creates a secret in the testing namespace
func (f *Framework) CreateSecret(secret corev1.Secret) {
func (f *Framework) CreateSecret(s corev1.Secret) {
if f.err != nil {
return
}

f.t.Logf("creating secret %s", secret.Name)
_, err := f.k8s.CoreV1().Secrets("test-cases").Create(context.Background(), &secret, metav1.CreateOptions{})
f.t.Logf("creating secret %s", s.Name)
_, err := f.k8s.CoreV1().Secrets(s.Namespace).Create(context.Background(), &s, metav1.CreateOptions{})
if err != nil {
f.err = err
return
}
f.t.Logf("secret %s created", secret.Name)
f.t.Logf("secret %s created", s.Name)
}

// WaitForDeployment waits until the deployment is ready
Expand Down Expand Up @@ -207,15 +207,15 @@ func (f *Framework) WaitForDeployment(d appsv1.Deployment) {
case event := <-w.ResultChan():
deployment, ok := event.Object.(*appsv1.Deployment)
if !ok {
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
continue
}

if deployment.Status.ReadyReplicas == 1 {
f.t.Logf("deployment %s is ready", d.Name)
return
}
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
}
}
}
Expand All @@ -226,7 +226,7 @@ func (f *Framework) waitForReplicaSetCreation(d appsv1.Deployment) string {
return ""
}

rs, err := f.k8s.AppsV1().ReplicaSets("test-cases").Watch(context.Background(), metav1.ListOptions{
rs, err := f.k8s.AppsV1().ReplicaSets(d.Namespace).Watch(context.Background(), metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", d.Name),
})
if err != nil {
Expand All @@ -247,7 +247,7 @@ func (f *Framework) waitForReplicaSetCreation(d appsv1.Deployment) string {
f.t.Logf("replicaset %s created", rs.Name)
return rs.Name
}
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
}
}
}
Expand All @@ -267,7 +267,7 @@ func (f *Framework) AssertDeploymentFailed(d appsv1.Deployment) {
}

// get warning events of deployment's namespace and check if the deployment failed
w, err := f.k8s.CoreV1().Events("test-cases").Watch(context.Background(), metav1.ListOptions{
w, err := f.k8s.CoreV1().Events(d.Namespace).Watch(context.Background(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("involvedObject.name=%s", rsName),
})
if err != nil {
Expand All @@ -285,14 +285,14 @@ func (f *Framework) AssertDeploymentFailed(d appsv1.Deployment) {
case event := <-w.ResultChan():
e, ok := event.Object.(*corev1.Event)
if !ok {
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
continue
}
if e.Reason == "FailedCreate" {
f.t.Logf("deployment %s failed: %s", d.Name, e.Message)
return
}
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
}
}
}
Expand All @@ -306,7 +306,7 @@ func (f *Framework) AssertEventForPod(reason string, p corev1.Pod) {
f.t.Logf("waiting for %s event to be created for pod %s", reason, p.Name)

// watch for events of deployment's namespace and check if the podverified event is created
w, err := f.k8s.CoreV1().Events("test-cases").Watch(context.Background(), metav1.ListOptions{
w, err := f.k8s.CoreV1().Events(p.Namespace).Watch(context.Background(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("involvedObject.name=%s", p.Name),
})
if err != nil {
Expand All @@ -324,14 +324,14 @@ func (f *Framework) AssertEventForPod(reason string, p corev1.Pod) {
case event := <-w.ResultChan():
e, ok := event.Object.(*corev1.Event)
if !ok {
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
continue
}
if e.Reason == reason {
f.t.Logf("%s event created for pod %s", reason, p.Name)
return
}
time.Sleep(5 * time.Second)
time.Sleep(500 * time.Millisecond)
}
}
}
5 changes: 4 additions & 1 deletion test/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"fmt"
"testing"

"github.com/eumel8/cosignwebhook/test/framework"
Expand All @@ -26,7 +27,8 @@ func TestPassECDSA(t *testing.T) {
}

for name, tf := range testFuncs {
t.Run(name, tf(fw, framework.CreateECDSAKeyPair, name))
t.Run(fmt.Sprintf("[%s] %s", "ECDSA", name), tf(fw, framework.CreateECDSAKeyPair, name))
t.Run(fmt.Sprintf("[%s] %s", "RSA", name), tf(fw, framework.CreateRSAKeyPair, name))
}
}

Expand All @@ -46,5 +48,6 @@ func TestFailingDeployments(t *testing.T) {

for name, tf := range testFuncs {
t.Run(name, tf(fw, framework.CreateECDSAKeyPair, name))
t.Run(name, tf(fw, framework.CreateRSAKeyPair, name))
}
}

0 comments on commit 8cd36fa

Please sign in to comment.