This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0096ecd
commit 3c01d27
Showing
5 changed files
with
315 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,86 @@ | ||
package component_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
||
"github.com/crossplane/oam-kubernetes-runtime/apis/core" | ||
) | ||
|
||
var scheme = runtime.NewScheme() | ||
var crd crdv1.CustomResourceDefinition | ||
var reqResource metav1.GroupVersionResource | ||
var decoder *admission.Decoder | ||
|
||
func TestMetrics(t *testing.T) { | ||
func TestComponentWebHandler(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Metrics Suite") | ||
RunSpecs(t, "Component Web handler") | ||
} | ||
|
||
var _ = BeforeSuite(func(done Done) { | ||
By("Bootstrapping test environment") | ||
err := clientgoscheme.AddToScheme(scheme) | ||
ctrl.SetLogger(zap.New(func(o *zap.Options) { | ||
o.Development = true | ||
o.DestWritter = os.Stderr | ||
})) | ||
By("Setup scheme") | ||
err := core.AddToScheme(scheme) | ||
Expect(err).Should(BeNil()) | ||
err = core.AddToScheme(scheme) | ||
err = clientgoscheme.AddToScheme(scheme) | ||
Expect(err).Should(BeNil()) | ||
err = crdv1.AddToScheme(scheme) | ||
// the crd we will refer to | ||
crd = crdv1.CustomResourceDefinition{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo.example.com", | ||
Labels: map[string]string{"crd": "dependency"}, | ||
}, | ||
Spec: crdv1.CustomResourceDefinitionSpec{ | ||
Group: "example.com", | ||
Names: crdv1.CustomResourceDefinitionNames{ | ||
Kind: "Foo", | ||
ListKind: "FooList", | ||
Plural: "foo", | ||
Singular: "foo", | ||
}, | ||
Versions: []crdv1.CustomResourceDefinitionVersion{ | ||
{ | ||
Name: "v1", | ||
Served: true, | ||
Storage: true, | ||
Schema: &crdv1.CustomResourceValidation{ | ||
OpenAPIV3Schema: &crdv1.JSONSchemaProps{ | ||
Type: "object", | ||
Properties: map[string]crdv1.JSONSchemaProps{ | ||
"status": { | ||
Type: "object", | ||
Properties: map[string]crdv1.JSONSchemaProps{ | ||
"key": {Type: "string"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Scope: crdv1.NamespaceScoped, | ||
}, | ||
} | ||
By("Prepare for the admission resource") | ||
reqResource = metav1.GroupVersionResource{Group: "core.oam.dev", Version: "v1alpha2", Resource: "components"} | ||
By("Prepare for the admission decoder") | ||
decoder, err = admission.NewDecoder(scheme) | ||
Expect(err).Should(BeNil()) | ||
By("Finished test bootstrap") | ||
close(done) | ||
}) |
Oops, something went wrong.