-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from razo7/dummy-E2E
Dummy e2e Test
- Loading branch information
Showing
4 changed files
with
139 additions
and
3 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
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
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,67 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/go-logr/logr" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
ctrl "sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
"github.com/medik8s/fence-agents-remediation/api/v1alpha1" | ||
) | ||
|
||
// These tests use Ginkgo (BDD-style Go testing framework). Refer to | ||
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. | ||
var ( | ||
log logr.Logger | ||
clientSet *kubernetes.Clientset | ||
k8sClient ctrl.Client | ||
) | ||
|
||
func TestE2e(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "FAR e2e suite") | ||
} | ||
|
||
var _ = BeforeSuite(func() { | ||
opts := zap.Options{ | ||
Development: true, | ||
TimeEncoder: zapcore.RFC3339NanoTimeEncoder, | ||
} | ||
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseFlagOptions(&opts))) | ||
log = logf.Log | ||
|
||
// +kubebuilder:scaffold:scheme | ||
|
||
// get the k8sClient or die | ||
config, err := config.GetConfig() | ||
if err != nil { | ||
Fail(fmt.Sprintf("Couldn't get kubeconfig %v", err)) | ||
} | ||
clientSet, err = kubernetes.NewForConfig(config) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(clientSet).NotTo(BeNil()) | ||
|
||
scheme.AddToScheme(scheme.Scheme) | ||
err = v1alpha1.AddToScheme(scheme.Scheme) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
k8sClient, err = ctrl.New(config, ctrl.Options{Scheme: scheme.Scheme}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
debug() | ||
}) | ||
|
||
func debug() { | ||
version, _ := clientSet.ServerVersion() | ||
fmt.Fprint(GinkgoWriter, version) | ||
} |
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,64 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
apiErrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/medik8s/fence-agents-remediation/api/v1alpha1" | ||
) | ||
|
||
const fenceAgentDummyName = "echo" | ||
|
||
var _ = Describe("FAR E2e", func() { | ||
Context("fence agent - dummy", func() { | ||
var far *v1alpha1.FenceAgentsRemediation | ||
testNodeName := "dummy-node" | ||
|
||
BeforeEach(func() { | ||
testShareParam := map[v1alpha1.ParameterName]string{} | ||
testNodeParam := map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string{} | ||
far = createFAR(testNodeName, fenceAgentDummyName, testShareParam, testNodeParam) | ||
}) | ||
|
||
AfterEach(func() { | ||
deleteFAR(far) | ||
}) | ||
|
||
It("should check whether the CR has been created", func() { | ||
testFarCR := &v1alpha1.FenceAgentsRemediation{} | ||
Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(far), testFarCR)).To(Succeed(), "failed to get FAR CR") | ||
}) | ||
}) | ||
}) | ||
|
||
// createFAR assigns the input to FenceAgentsRemediation object, creates CR with offset, and returns the CR object | ||
func createFAR(nodeName string, agent string, sharedParameters map[v1alpha1.ParameterName]string, nodeParameters map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string) *v1alpha1.FenceAgentsRemediation { | ||
far := &v1alpha1.FenceAgentsRemediation{ | ||
ObjectMeta: metav1.ObjectMeta{Name: nodeName}, | ||
Spec: v1alpha1.FenceAgentsRemediationSpec{ | ||
Agent: agent, | ||
SharedParameters: sharedParameters, | ||
NodeParameters: nodeParameters, | ||
}, | ||
} | ||
ExpectWithOffset(1, k8sClient.Create(context.Background(), far)).ToNot(HaveOccurred()) | ||
return far | ||
} | ||
|
||
// deleteFAR deletes the CR with offset | ||
func deleteFAR(far *v1alpha1.FenceAgentsRemediation) { | ||
EventuallyWithOffset(1, func() error { | ||
err := k8sClient.Delete(context.Background(), far) | ||
if apiErrors.IsNotFound(err) { | ||
return nil | ||
} | ||
return err | ||
}, 2*time.Minute, 10*time.Second).ShouldNot(HaveOccurred(), "failed to delete far") | ||
} |