-
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.
The test works fine but for some reason the AfterSuite tear down function isn't working as expected. It times out after trying to shut down the API server. The test comes back as passed but because the API server won't shut down in time, `make test` fails. kubernetes-sigs/controller-runtime#1571
- Loading branch information
1 parent
d1b6640
commit 1f41401
Showing
2 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
tacomoev1alpha1 "github.com/ryanmillerc/cat-facts-operator/api/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
var _ = Describe("CatFact controller", func() { | ||
|
||
// Define utility constants for object names and testing timeouts/durations and intervals. | ||
const ( | ||
CatFactName = "my-cat-fact" | ||
CatFactNamespace = "default" | ||
|
||
timeout = time.Second * 10 | ||
duration = time.Second * 10 | ||
interval = time.Millisecond * 250 | ||
) | ||
|
||
Context("When creating a CatFact", func() { | ||
It("Should generate a fact if a fact isn't provided", func() { | ||
By("Magic") | ||
ctx := context.Background() | ||
catFact := &tacomoev1alpha1.CatFact{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "taco.moe/v1alpha1", | ||
Kind: "CatFact", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: CatFactName, | ||
Namespace: CatFactNamespace, | ||
}, | ||
Spec: tacomoev1alpha1.CatFactSpec{ | ||
Fact: "", | ||
}, | ||
} | ||
Expect(k8sClient.Create(ctx, catFact)).Should(Succeed()) | ||
|
||
catFactLookupKey := types.NamespacedName{Name: CatFactName, Namespace: CatFactNamespace} | ||
createdCatFact := &tacomoev1alpha1.CatFact{} | ||
|
||
// We'll need to retry getting this newly created CronJob, given that creation may not immediately happen. | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, catFactLookupKey, createdCatFact) | ||
if err != nil { | ||
return false | ||
} | ||
return true | ||
}, timeout, interval).Should(BeTrue()) | ||
// Let's make sure a fact was set on the object | ||
Expect(createdCatFact.Spec.Fact).Should(Equal("")) | ||
}) | ||
}) | ||
}) |
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