Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Ginkgo v2 #750

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ envtest: setup-envtest
source <($(SETUP_ENVTEST) use -p env); \
export MOCO_CHECK_INTERVAL=100ms; \
export MOCO_CLONE_WAIT_DURATION=100ms; \
go test -v -count 1 -race ./clustering -ginkgo.progress -ginkgo.v -ginkgo.failFast
go test -v -count 1 -race ./clustering -ginkgo.randomize-all -ginkgo.v -ginkgo.fail-fast
source <($(SETUP_ENVTEST) use -p env); \
export DEBUG_CONTROLLER=1; \
go test -v -count 1 -race ./controllers -ginkgo.progress -ginkgo.v -ginkgo.failFast
go test -v -count 1 -race ./controllers -ginkgo.randomize-all -ginkgo.v -ginkgo.fail-fast
source <($(SETUP_ENVTEST) use -p env); \
go test -v -count 1 -race ./api/... -ginkgo.progress -ginkgo.v
go test -v -count 1 -race ./api/... -ginkgo.randomize-all -ginkgo.v
source <($(SETUP_ENVTEST) use -p env); \
go test -v -count 1 -race ./backup -ginkgo.progress -ginkgo.v -ginkgo.failFast
go test -v -count 1 -race ./backup -ginkgo.randomize-all -ginkgo.v -ginkgo.fail-fast

.PHONY: test-dbop
test-dbop:
-docker network create test-moco
TEST_MYSQL=1 MYSQL_VERSION=$(MYSQL_VERSION) go test -v -count 1 -race ./pkg/dbop -ginkgo.v
TEST_MYSQL=1 MYSQL_VERSION=$(MYSQL_VERSION) go test -v -count 1 -race ./pkg/dbop -ginkgo.v -ginkgo.randomize-all

.PHONY: test-bkop
test-bkop:
@if which mysqlsh; then : ; else echo 'Run "make setup" to prepare test tools.'; exit 1; fi
-docker network create test-moco
TEST_MYSQL=1 MYSQL_VERSION=$(MYSQL_VERSION) go test -v -count 1 -race ./pkg/bkop -ginkgo.v -ginkgo.progress
TEST_MYSQL=1 MYSQL_VERSION=$(MYSQL_VERSION) go test -v -count 1 -race ./pkg/bkop -ginkgo.v -ginkgo.randomize-all

.PHONY: test
test: test-tools
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/backuppolicy_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
batchv1 "k8s.io/api/batch/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/mysqlcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
"github.com/cybozu-go/moco/pkg/constants"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/statefulset_webhhok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v1beta2_test
import (
"context"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta2/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -123,7 +123,7 @@ var _ = BeforeSuite(func() {
return nil
}).Should(Succeed())

}, 60)
})

var _ = AfterSuite(func() {
cancel()
Expand Down
2 changes: 1 addition & 1 deletion backup/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
"github.com/cybozu-go/moco/pkg/bkop"
"github.com/cybozu-go/moco/pkg/constants"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
Expand Down
4 changes: 2 additions & 2 deletions backup/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -79,7 +79,7 @@ var _ = BeforeSuite(func() {
err = k8sClient.Create(context.Background(), ns)
Expect(err).NotTo(HaveOccurred())

}, 60)
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
Expand Down
4 changes: 2 additions & 2 deletions clustering/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cybozu-go/moco/pkg/event"
"github.com/cybozu-go/moco/pkg/metrics"
"github.com/go-logr/stdr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/prometheus/client_golang/prometheus"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -145,7 +145,7 @@ var _ = Describe("manager", func() {
time.Sleep(10 * time.Millisecond)
})
JustAfterEach(func() {
if CurrentGinkgoTestDescription().Failed {
if CurrentSpecReport().Failed() {
cluster, err := testGetCluster(ctx)
if err == nil {
enc := json.NewEncoder(os.Stdout)
Expand Down
4 changes: 2 additions & 2 deletions clustering/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -76,7 +76,7 @@ var _ = BeforeSuite(func() {

mysqlPassword, err = password.NewMySQLPassword()
Expect(err).NotTo(HaveOccurred())
}, 60)
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
Expand Down
111 changes: 61 additions & 50 deletions controllers/mysqlcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
"github.com/cybozu-go/moco/pkg/constants"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -64,6 +64,58 @@ func testNewMySQLCluster(ns string) *mocov1beta2.MySQLCluster {
return cluster
}

func testNewBackUpPolicy() *mocov1beta2.BackupPolicy {
bp := &mocov1beta2.BackupPolicy{}
bp.Namespace = "test"
bp.Name = "test-policy"
bp.Spec.ActiveDeadlineSeconds = ptr.To[int64](100)
bp.Spec.BackoffLimit = ptr.To[int32](1)
bp.Spec.ConcurrencyPolicy = batchv1.ForbidConcurrent
bp.Spec.StartingDeadlineSeconds = ptr.To[int64](10)
bp.Spec.Schedule = "*/5 * * * *"
bp.Spec.SuccessfulJobsHistoryLimit = ptr.To[int32](1)
bp.Spec.FailedJobsHistoryLimit = ptr.To[int32](2)
jc := &bp.Spec.JobConfig
jc.Threads = 3
jc.ServiceAccountName = "foo"
jc.CPU = resource.NewQuantity(1, resource.DecimalSI)
jc.MaxCPU = resource.NewQuantity(4, resource.DecimalSI)
jc.Memory = resource.NewQuantity(1<<30, resource.DecimalSI)
jc.MaxMemory = resource.NewQuantity(10<<30, resource.DecimalSI)
jc.Env = []mocov1beta2.EnvVarApplyConfiguration{{Name: ptr.To[string]("TEST"), Value: ptr.To[string]("123")}}
jc.EnvFrom = []mocov1beta2.EnvFromSourceApplyConfiguration{
{
ConfigMapRef: &corev1ac.ConfigMapEnvSourceApplyConfiguration{
LocalObjectReferenceApplyConfiguration: corev1ac.LocalObjectReferenceApplyConfiguration{
Name: ptr.To[string]("bucket-config"),
},
},
},
}
jc.WorkVolume = mocov1beta2.VolumeSourceApplyConfiguration{
EmptyDir: &corev1ac.EmptyDirVolumeSourceApplyConfiguration{},
}
jc.Volumes = []mocov1beta2.VolumeApplyConfiguration{
{
Name: ptr.To[string]("test"),
VolumeSourceApplyConfiguration: corev1ac.VolumeSourceApplyConfiguration{
EmptyDir: &corev1ac.EmptyDirVolumeSourceApplyConfiguration{},
},
},
}
jc.VolumeMounts = []mocov1beta2.VolumeMountApplyConfiguration{
{
Name: ptr.To[string]("test"),
MountPath: ptr.To[string]("/path/to/dir"),
},
}
jc.BucketConfig.BucketName = "mybucket"
jc.BucketConfig.EndpointURL = "https://foo.bar.baz"
jc.BucketConfig.Region = "us-east-1"
jc.BucketConfig.UsePathStyle = true
return bp
}

func testDeleteMySQLCluster(ctx context.Context, ns, name string) {
cluster := &mocov1beta2.MySQLCluster{}
cluster.Namespace = ns
Expand Down Expand Up @@ -95,6 +147,8 @@ var _ = Describe("MySQLCluster reconciler", func() {
}
err = k8sClient.DeleteAllOf(ctx, &mocov1beta2.MySQLCluster{}, client.InNamespace("test"))
Expect(err).NotTo(HaveOccurred())
err = k8sClient.DeleteAllOf(ctx, &mocov1beta2.BackupPolicy{}, client.InNamespace("test"))
Expect(err).NotTo(HaveOccurred())
err = k8sClient.DeleteAllOf(ctx, &appsv1.StatefulSet{}, client.InNamespace("test"))
Expect(err).NotTo(HaveOccurred())
err = k8sClient.DeleteAllOf(ctx, &corev1.Secret{}, client.InNamespace("test"))
Expand Down Expand Up @@ -1251,54 +1305,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
Expect(err).NotTo(HaveOccurred())

By("creating a backup policy")
bp := &mocov1beta2.BackupPolicy{}
bp.Namespace = "test"
bp.Name = "test-policy"
bp.Spec.ActiveDeadlineSeconds = ptr.To[int64](100)
bp.Spec.BackoffLimit = ptr.To[int32](1)
bp.Spec.ConcurrencyPolicy = batchv1.ForbidConcurrent
bp.Spec.StartingDeadlineSeconds = ptr.To[int64](10)
bp.Spec.Schedule = "*/5 * * * *"
bp.Spec.SuccessfulJobsHistoryLimit = ptr.To[int32](1)
bp.Spec.FailedJobsHistoryLimit = ptr.To[int32](2)
jc := &bp.Spec.JobConfig
jc.Threads = 3
jc.ServiceAccountName = "foo"
jc.CPU = resource.NewQuantity(1, resource.DecimalSI)
jc.MaxCPU = resource.NewQuantity(4, resource.DecimalSI)
jc.Memory = resource.NewQuantity(1<<30, resource.DecimalSI)
jc.MaxMemory = resource.NewQuantity(10<<30, resource.DecimalSI)
jc.Env = []mocov1beta2.EnvVarApplyConfiguration{{Name: ptr.To[string]("TEST"), Value: ptr.To[string]("123")}}
jc.EnvFrom = []mocov1beta2.EnvFromSourceApplyConfiguration{
{
ConfigMapRef: &corev1ac.ConfigMapEnvSourceApplyConfiguration{
LocalObjectReferenceApplyConfiguration: corev1ac.LocalObjectReferenceApplyConfiguration{
Name: ptr.To[string]("bucket-config"),
},
},
},
}
jc.WorkVolume = mocov1beta2.VolumeSourceApplyConfiguration{
EmptyDir: &corev1ac.EmptyDirVolumeSourceApplyConfiguration{},
}
jc.Volumes = []mocov1beta2.VolumeApplyConfiguration{
{
Name: ptr.To[string]("test"),
VolumeSourceApplyConfiguration: corev1ac.VolumeSourceApplyConfiguration{
EmptyDir: &corev1ac.EmptyDirVolumeSourceApplyConfiguration{},
},
},
}
jc.VolumeMounts = []mocov1beta2.VolumeMountApplyConfiguration{
{
Name: ptr.To[string]("test"),
MountPath: ptr.To[string]("/path/to/dir"),
},
}
jc.BucketConfig.BucketName = "mybucket"
jc.BucketConfig.EndpointURL = "https://foo.bar.baz"
jc.BucketConfig.Region = "us-east-1"
jc.BucketConfig.UsePathStyle = true
bp := testNewBackUpPolicy()
err = k8sClient.Create(ctx, bp)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -1386,7 +1393,7 @@ var _ = Describe("MySQLCluster reconciler", func() {
bp.Spec.Schedule = "*/5 1 * * *"
bp.Spec.SuccessfulJobsHistoryLimit = nil
bp.Spec.FailedJobsHistoryLimit = nil
jc = &bp.Spec.JobConfig
jc := &bp.Spec.JobConfig
jc.Threads = 1
jc.ServiceAccountName = "oof"
jc.CPU = nil
Expand Down Expand Up @@ -1658,6 +1665,10 @@ var _ = Describe("MySQLCluster reconciler", func() {
err := k8sClient.Create(ctx, cluster)
Expect(err).NotTo(HaveOccurred())

bp := testNewBackUpPolicy()
err = k8sClient.Create(ctx, bp)
Expect(err).NotTo(HaveOccurred())

var cj *batchv1.CronJob
var pdb *policyv1.PodDisruptionBudget
Eventually(func() error {
Expand Down
2 changes: 1 addition & 1 deletion controllers/partition_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sort"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion controllers/pod_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
12 changes: 9 additions & 3 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -53,7 +53,13 @@ var _ = BeforeSuite(func() {
}

var err error
cfg, err = testEnv.Start()
done := make(chan interface{})
go func() {
defer GinkgoRecover()
cfg, err = testEnv.Start()
close(done)
}()
Eventually(done).WithTimeout(time.Minute).Should(BeClosed())
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

Expand Down Expand Up @@ -84,7 +90,7 @@ var _ = BeforeSuite(func() {
err = k8sClient.Create(context.Background(), ns)
Expect(err).NotTo(HaveOccurred())

}, 60)
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
Expand Down
4 changes: 2 additions & 2 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ endif
.PHONY: test
test:
env PATH="$$(pwd)/../bin:$$PATH" RUN_E2E=1 \
go test -v -race -timeout 90m . -ginkgo.progress -ginkgo.v -ginkgo.failFast
go test -v -race -timeout 90m . -ginkgo.v -ginkgo.fail-fast -ginkgo.randomize-all -ginkgo.timeout 90m

.PHONY: test-upgrade
test-upgrade:
env PATH=$$(pwd)/../bin:$$PATH RUN_E2E=1 UPGRADE=1 \
go test -v -race -timeout 15m . -ginkgo.progress -ginkgo.v -ginkgo.failFast
go test -v -race -timeout 15m . -ginkgo.v -ginkgo.fail-fast -ginkgo.randomize-all

.PHONY: logs
logs:
Expand Down
4 changes: 2 additions & 2 deletions e2e/backup_gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -25,7 +25,7 @@ var backupGCSYAML string
//go:embed testdata/restore_gcs.yaml
var restoreGCSYAML string

var _ = Context("backup-gcs", func() {
var _ = Context("backup-gcs", Ordered, func() {
if doUpgrade {
return
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -29,7 +29,7 @@ var restore1YAML string
//go:embed testdata/restore2.yaml
var restore2YAML string

var _ = Context("backup", func() {
var _ = Context("backup", Ordered, func() {
if doUpgrade {
return
}
Expand Down
Loading