use TestMain
This commit is contained in:
parent
93b6e7fa31
commit
8243fa121c
|
|
@ -28,6 +28,10 @@ const (
|
|||
func TestAutoscalitRunnerSetReconciler_CreateRunnerScaleSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
eventually := eventually.New(
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval),
|
||||
)
|
||||
autoscalingNS, mgr := createNamespace(t)
|
||||
configSecret := createDefaultSecret(t, autoscalingNS.Name)
|
||||
|
||||
|
|
@ -55,9 +59,7 @@ func TestAutoscalitRunnerSetReconciler_CreateRunnerScaleSet(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Len(t, created.Finalizers, 1)
|
||||
assert.Equal(t, created.Finalizers[0], autoscalingRunnerSetFinalizerName)
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Check if runner scale set is created on service
|
||||
eventually.Must(t, func(t testing.TB) {
|
||||
|
|
@ -69,9 +71,7 @@ func TestAutoscalitRunnerSetReconciler_CreateRunnerScaleSet(t *testing.T) {
|
|||
|
||||
require.Contains(t, created.Annotations, runnerScaleSetRunnerGroupNameKey)
|
||||
assert.Equal(t, "testgroup", created.Annotations[runnerScaleSetRunnerGroupNameKey])
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Check if ephemeral runner set is created
|
||||
eventually.Must(t, func(t testing.TB) {
|
||||
|
|
@ -79,17 +79,13 @@ func TestAutoscalitRunnerSetReconciler_CreateRunnerScaleSet(t *testing.T) {
|
|||
err := k8sClient.List(ctx, runnerSetList, client.InNamespace(autoscalingRunnerSet.Namespace))
|
||||
require.NoError(t, err)
|
||||
require.Len(t, runnerSetList.Items, 1)
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Check if listener is created
|
||||
eventually.Must(t, func(t testing.TB) {
|
||||
err := k8sClient.Get(ctx, client.ObjectKey{Name: scaleSetListenerName(autoscalingRunnerSet), Namespace: autoscalingRunnerSet.Namespace}, new(v1alpha1.AutoscalingListener))
|
||||
require.NoError(t, err)
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Check if status is updated
|
||||
runnerSetList := new(v1alpha1.EphemeralRunnerSetList)
|
||||
|
|
@ -101,6 +97,10 @@ func TestAutoscalitRunnerSetReconciler_CreateRunnerScaleSet(t *testing.T) {
|
|||
func TestAutoscalitRunnerSetReconciler_DeleteRunnerScaleSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx := context.Background()
|
||||
eventually := eventually.New(
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval),
|
||||
)
|
||||
autoscalingNS, mgr := createNamespace(t)
|
||||
configSecret := createDefaultSecret(t, autoscalingNS.Name)
|
||||
|
||||
|
|
@ -132,9 +132,7 @@ func TestAutoscalitRunnerSetReconciler_DeleteRunnerScaleSet(t *testing.T) {
|
|||
new(v1alpha1.AutoscalingListener),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Delete the AutoScalingRunnerSet
|
||||
err = k8sClient.Delete(ctx, autoscalingRunnerSet)
|
||||
|
|
@ -145,9 +143,7 @@ func TestAutoscalitRunnerSetReconciler_DeleteRunnerScaleSet(t *testing.T) {
|
|||
err := k8sClient.Get(ctx, client.ObjectKey{Name: scaleSetListenerName(autoscalingRunnerSet), Namespace: autoscalingRunnerSet.Namespace}, new(v1alpha1.AutoscalingListener))
|
||||
require.NotNil(t, err)
|
||||
assert.True(t, errors.IsNotFound(err))
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Check if all the EphemeralRunnerSet is deleted
|
||||
eventually.Must(t, func(t testing.TB) {
|
||||
|
|
@ -155,18 +151,14 @@ func TestAutoscalitRunnerSetReconciler_DeleteRunnerScaleSet(t *testing.T) {
|
|||
err := k8sClient.List(ctx, runnerSetList, client.InNamespace(autoscalingRunnerSet.Namespace))
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, runnerSetList.Items, 0, "All EphemeralRunnerSet should be deleted")
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
|
||||
// Check if the AutoScalingRunnerSet is deleted
|
||||
eventually.Must(t, func(t testing.TB) {
|
||||
err := k8sClient.Get(ctx, client.ObjectKey{Name: autoscalingRunnerSet.Name, Namespace: autoscalingRunnerSet.Namespace}, new(v1alpha1.AutoscalingRunnerSet))
|
||||
require.NotNil(t, err)
|
||||
assert.True(t, errors.IsNotFound(err))
|
||||
},
|
||||
eventually.WithTimeout(autoscalingRunnerSetTestTimeout),
|
||||
eventually.WithInterval(autoscalingRunnerSetTestInterval))
|
||||
})
|
||||
}
|
||||
|
||||
// var _ = Describe("Test AutoScalingRunnerSet controller", func() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
package actionsgithubcom
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
actionsv1alpha1 "github.com/actions/actions-runner-controller/apis/actions.github.com/v1alpha1"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *rest.Config
|
||||
k8sClient client.Client
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
logf.SetLogger(zap.New(zap.UseDevMode(true), zap.WriteTo(io.Discard)))
|
||||
|
||||
testEnv := &envtest.Environment{
|
||||
CRDDirectoryPaths: []string{filepath.Join("../..", "config", "crd", "bases")},
|
||||
}
|
||||
|
||||
// Avoids the following error:
|
||||
// 2021-03-19T15:14:11.673+0900 ERROR controller-runtime.controller
|
||||
// Reconciler error {"controller": "testns-tvjzjrunner", "request":
|
||||
// "testns-gdnyx/example-runnerdeploy-zps4z-j5562", "error": "Pod
|
||||
// \"example-runnerdeploy-zps4z-j5562\" is invalid:
|
||||
// [spec.containers[1].image: Required value,
|
||||
// spec.containers[1].securityContext.privileged: Forbidden: disallowed by
|
||||
// cluster policy]"}
|
||||
testEnv.ControlPlane.GetAPIServer().Configure().
|
||||
Append("allow-privileged", "true")
|
||||
|
||||
var err error
|
||||
cfg, err = testEnv.Start()
|
||||
if err != nil || cfg == nil {
|
||||
log.Fatalln(err, "failed to start test environment")
|
||||
}
|
||||
|
||||
err = actionsv1alpha1.AddToScheme(scheme.Scheme)
|
||||
if err != nil {
|
||||
log.Fatalln(err, "failed to add scheme")
|
||||
}
|
||||
|
||||
// +kubebuilder:scaffold:scheme
|
||||
|
||||
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
|
||||
if err != nil || k8sClient == nil {
|
||||
log.Fatalln(err, "failed to create client")
|
||||
}
|
||||
|
||||
// run the tests
|
||||
code := m.Run()
|
||||
|
||||
err = testEnv.Stop()
|
||||
if err != nil {
|
||||
log.Fatalln(err, "failed to stop test environment")
|
||||
}
|
||||
|
||||
os.Exit(code)
|
||||
}
|
||||
2
go.mod
2
go.mod
|
|
@ -22,7 +22,7 @@ require (
|
|||
github.com/onsi/gomega v1.27.2
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/rentziass/eventually v0.0.0-20230322104408-065f0b6d63a2
|
||||
github.com/rentziass/eventually v0.2.0
|
||||
github.com/stretchr/testify v1.8.2
|
||||
github.com/teambition/rrule-go v1.8.2
|
||||
go.uber.org/multierr v1.7.0
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -333,8 +333,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
|
|||
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
|
||||
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
|
||||
github.com/rentziass/eventually v0.0.0-20230322104408-065f0b6d63a2 h1:4efabAGkX7mmXAztMNdorD35hzPW9hQxP9GLn6NfgFo=
|
||||
github.com/rentziass/eventually v0.0.0-20230322104408-065f0b6d63a2/go.mod h1:jiSDJFv0sra6DK66duTH5V4kCfqd9OvmFtflPOExNVI=
|
||||
github.com/rentziass/eventually v0.2.0 h1:zC6GB2nRRlARqfngNGUmdKG5Z6cOwyc0BwleF8kcZHY=
|
||||
github.com/rentziass/eventually v0.2.0/go.mod h1:jiSDJFv0sra6DK66duTH5V4kCfqd9OvmFtflPOExNVI=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
|
|
|
|||
Loading…
Reference in New Issue