diff --git a/pkg/nsx/services/common/types.go b/pkg/nsx/services/common/types.go index 85044ac6e..f8f10cdb4 100644 --- a/pkg/nsx/services/common/types.go +++ b/pkg/nsx/services/common/types.go @@ -170,6 +170,7 @@ var ( ResourceTypeIPAddressAllocation = "VpcIpAddressAllocation" ResourceTypeIPPoolBlockSubnet = "IpAddressPoolBlockSubnet" ResourceTypeNode = "HostTransportNode" + ResourceTypeStaticRoute = "StaticRoutes" ) type Service struct { diff --git a/test/e2e/manifest/testStaticRoute/staticroute.yaml b/test/e2e/manifest/testStaticRoute/staticroute.yaml new file mode 100644 index 000000000..629cbf4b6 --- /dev/null +++ b/test/e2e/manifest/testStaticRoute/staticroute.yaml @@ -0,0 +1,8 @@ +apiVersion: nsx.vmware.com/v1alpha1 +kind: StaticRoute +metadata: + name: guestcluster-staticroute-2 +spec: + network: 45.1.2.0/24 + nextHops: + - ipAddress: 172.10.0.2 diff --git a/test/e2e/nsx_staticroute_test.go b/test/e2e/nsx_staticroute_test.go new file mode 100644 index 000000000..5596218bd --- /dev/null +++ b/test/e2e/nsx_staticroute_test.go @@ -0,0 +1,45 @@ +// This file is for e2e StaticRoute tests. + +package e2e + +import ( + "path/filepath" + "testing" + + "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common" +) + +const ( + StaticRoute = "StaticRoute" +) + +// TestStaticRouteBasic verifies that it could successfully realize StaticRoute. +func TestStaticRouteBasic(t *testing.T) { + ns := "sc-a" + name := "guestcluster-staticroute-2" + setupTest(t, ns) + defer teardownTest(t, ns, defaultTimeout) + + // Create StaticRoute + StaticRoutePath, _ := filepath.Abs("./manifest/testStaticRoute/staticroute.yaml") + err := applyYAML(StaticRoutePath, ns) + if err != nil { + t.Fatalf("Failed to apply StaticRoute YAML file: %v", err) + } + assertNil(t, err) + + // Check StaticRoute status + err = testData.waitForCRReadyOrDeleted(defaultTimeout, StaticRoute, ns, name, Ready) + assertNil(t, err, "Error when waiting for Static Route %s", name) + + // Check nsx-t resource existing + err = testData.waitForResourceExistOrNot(ns, common.ResourceTypeStaticRoute, name, true) + assertNil(t, err) + + // Delete StaticRoute + _ = deleteYAML(StaticRoutePath, ns) + + // Check nsx-t resource not existing + err = testData.waitForResourceExistOrNot(ns, common.ResourceTypeStaticRoute, name, false) + assertNil(t, err) +}