Skip to content

Commit

Permalink
Add staticroute e2e test
Browse files Browse the repository at this point in the history
Add staticroute e2e test
  • Loading branch information
TaoZou1 committed Nov 5, 2024
1 parent 2b6d1b7 commit 4063b71
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/nsx/services/staticroute/staticroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (service *StaticRouteService) DeleteStaticRouteByPath(orgId string, project
return err
}

log.Info("successfully deleted NSX StaticRoute", "nsxStaticRoute", *staticroute.Id)
log.Info("Successfully deleted NSX StaticRoute", "nsxStaticRoute", *staticroute.Id)
return nil
}
func (service *StaticRouteService) GetUID(staticroute *model.StaticRoutes) *string {
Expand Down Expand Up @@ -173,17 +173,17 @@ func (service *StaticRouteService) ListStaticRoute() []*model.StaticRoutes {

func (service *StaticRouteService) Cleanup(ctx context.Context) error {
staticRouteSet := service.ListStaticRoute()
log.Info("cleanup staticroute", "count", len(staticRouteSet))
log.Info("Cleanup staticroute", "count", len(staticRouteSet))
for _, staticRoute := range staticRouteSet {
path := strings.Split(*staticRoute.Path, "/")
log.Info("removing staticroute", "staticroute path", *staticRoute.Path)
log.Info("Deleting staticroute", "staticroute path", *staticRoute.Path)
select {
case <-ctx.Done():
return errors.Join(nsxutil.TimeoutFailed, ctx.Err())
default:
err := service.DeleteStaticRouteByPath(path[2], path[4], path[6], *staticRoute.Id)
if err != nil {
log.Error(err, "remove staticroute failed", "staticroute id", *staticRoute.Id)
log.Error(err, "Delete staticroute failed", "staticroute id", *staticRoute.Id)
return err
}
}
Expand Down
45 changes: 45 additions & 0 deletions test/e2e/manifest/nsx_staticroute_test.go
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 20 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: setupTest
defer teardownTest(t, ns, defaultTimeout)

Check failure on line 21 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: teardownTest

Check failure on line 21 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: defaultTimeout

// Create StaticRoute
StaticRoutePath, _ := filepath.Abs("./manifest/testStaticRoute/staticroute.yaml")
err := applyYAML(StaticRoutePath, ns)

Check failure on line 25 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: applyYAML
if err != nil {
t.Fatalf("Failed to apply StaticRoute YAML file: %v", err)
}
assertNil(t, err)

Check failure on line 29 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: assertNil

// Check StaticRoute status
err = testData.waitForCRReadyOrDeleted(defaultTimeout, StaticRoute, ns, name, Ready)

Check failure on line 32 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: testData

Check failure on line 32 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: defaultTimeout

Check failure on line 32 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: Ready
assertNil(t, err, "Error when waiting for Static Route %s", name)

Check failure on line 33 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: assertNil

// Check nsx-t resource existing
err = testData.waitForResourceExistOrNot(ns, common.ResourceTypeStaticRoute, name, true)

Check failure on line 36 in test/e2e/manifest/nsx_staticroute_test.go

View workflow job for this annotation

GitHub Actions / build

undefined: testData
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)
}
8 changes: 8 additions & 0 deletions test/e2e/manifest/testStaticRoute/staticroute.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4063b71

Please sign in to comment.