-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
…EventMesh (#194) * code * fixed lint issues * added tests * addressed review comments
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package controller_switching | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
eventingv1alpha1 "github.com/kyma-project/eventing-manager/api/v1alpha1" | ||
"github.com/kyma-project/eventing-manager/test/matchers" | ||
"github.com/kyma-project/eventing-manager/test/utils" | ||
testutils "github.com/kyma-project/eventing-manager/test/utils/integration" | ||
"github.com/onsi/gomega" | ||
gomegatypes "github.com/onsi/gomega/types" | ||
) | ||
|
||
const ( | ||
projectRootDir = "../../../../../" | ||
) | ||
|
||
var testEnvironment *testutils.TestEnvironment //nolint:gochecknoglobals // used in tests | ||
|
||
// TestMain pre-hook and post-hook to run before and after all tests. | ||
func TestMain(m *testing.M) { | ||
// Note: The setup will provision a single K8s env and | ||
// all the tests need to create and use a separate namespace | ||
|
||
// setup env test | ||
var err error | ||
testEnvironment, err = testutils.NewTestEnvironment(testutils.TestEnvironmentConfig{ | ||
ProjectRootDir: projectRootDir, | ||
CELValidationEnabled: true, | ||
APIRuleCRDEnabled: false, | ||
ApplicationRuleCRDEnabled: true, | ||
NATSCRDEnabled: true, | ||
AllowedEventingCR: nil, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// run tests | ||
code := m.Run() | ||
|
||
// tear down test env | ||
if err = testEnvironment.TearDown(); err != nil { | ||
panic(err) | ||
} | ||
|
||
os.Exit(code) | ||
} | ||
|
||
// Test_EventMesh_APIRule_Dependency_Check tests that when the APIRule CRD is missing in case of EventMesh, | ||
// the Eventing CR should have Error status with a message. The success case where APIRule exists is | ||
// covered in integrationtests/controller/integration_test.go. | ||
func Test_EventMesh_APIRule_Dependency_Check(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
name string | ||
givenEventing *eventingv1alpha1.Eventing | ||
wantMatches gomegatypes.GomegaMatcher | ||
}{ | ||
{ | ||
name: "Eventing CR should error state due to APIRule CRD not available", | ||
givenEventing: utils.NewEventingCR( | ||
utils.WithEventMeshBackend("test-secret-name1"), | ||
utils.WithEventingPublisherData(1, 1, "199m", "99Mi", "399m", "199Mi"), | ||
utils.WithEventingEventTypePrefix("test-prefix"), | ||
utils.WithEventingDomain(utils.Domain), | ||
), | ||
wantMatches: gomega.And( | ||
matchers.HaveStatusError(), | ||
matchers.HaveEventMeshSubManagerNotReadyCondition( | ||
"API-Gateway module is needed for EventMesh backend. APIRules CRD is not installed"), | ||
), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
g := gomega.NewWithT(t) | ||
|
||
// given | ||
// create unique namespace for this test run. | ||
givenNamespace := tc.givenEventing.Namespace | ||
testEnvironment.EnsureNamespaceCreation(t, givenNamespace) | ||
|
||
// create eventing-webhook-auth secret. | ||
testEnvironment.EnsureOAuthSecretCreated(t, tc.givenEventing) | ||
|
||
// create EventMesh secret. | ||
testEnvironment.EnsureEventMeshSecretCreated(t, tc.givenEventing) | ||
|
||
// when | ||
// create Eventing CR. | ||
testEnvironment.EnsureK8sResourceCreated(t, tc.givenEventing) | ||
|
||
// then | ||
// check Eventing CR status. | ||
testEnvironment.GetEventingAssert(g, tc.givenEventing).Should(tc.wantMatches) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.