Skip to content

test/e2e: export types, functions, and package vars for external consumption#64

Open
josecastillolema wants to merge 14 commits into
NVIDIA:public-mainfrom
josecastillolema:export-tests
Open

test/e2e: export types, functions, and package vars for external consumption#64
josecastillolema wants to merge 14 commits into
NVIDIA:public-mainfrom
josecastillolema:export-tests

Conversation

@josecastillolema

Copy link
Copy Markdown

Exports the unexported types, functions, and package-level state throughout test/e2e so the suite can be consumed as a plain Go library import (import e2e "github.com/nvidia/doca-platform/test/e2e") from an external repository, instead of requiring go test internals or copy-pasted logic.

Why

Downstream consumers (e.g. openshift-dpf) want to run this suite's actual test logic against a pre-existing DPF deployment without reimplementing it. A prior PoC proved this is viable for one test (leader-election failover) by exporting a single struct. This PR generalizes that to the whole package.

What changed

  • SystemTestInput (the central struct used by ~35 of 42 files) type, all 43 fields, and its 4 methods exported; SetInput() now returns the constructed value instead of only mutating a package-private global.
  • ProvisionDPUClustersInput / DeployDPFSystemComponentsInput — were already exported types but every field was unexported (uninstantiable); fields exported.
  • Suite-level globals (Ctx, TestClient, RestConfig, Conf, CleanupFlags, DPUClusterClient, etc.) — exported so external callers can set them before invoking Validate*/Verify* functions, matching the package's existing global-state design.
  • Config type and shared namespace/name/timeout consts exported.
  • VPCOVN and Weave subsystems — previously had no exported entry point at all; their scenario logic was inlined directly in _test.go It() blocks calling ~19 and ~24 unexported helpers respectively. Fully exported (types, helpers, package-var singletons).
  • Upgrade framework (InstallPhase/ValidationPhase DSL, artifact snapshot/compare) — same "no facade" problem as VPCOVN/Weave; fully exported.
  • _test.go boundary fix (the critical one): Go excludes _test.go files from normal package imports, so SetInput, SystemSetupBeforeSuite, SDNBeforeSuite, VPCOVNBeforeSuite and their backing package vars were exported by name but still undefined to an external importer. Relocated 8 functions and ~12 package vars into new/existing non-test .go files: pure moves, zero logic changes.

All changes are mechanical renames/relocations — no test logic, assertions, or control flow were modified.

Verification

  • go build ./... (external-import path), go vet ./... and go test ./test/e2e/... -list '.*' (internal go test path) all pass.
  • Re-ran the original leader-election-failover PoC against a live cluster using this branch: passed in ~41s, cluster state restored correctly afterward (DeferCleanup scaled the controller back to 1 replica).

Assisted-by: Claude 🤖

Renames the central unexported systemTestInput struct (and all ~43
fields) to SystemTestInput so it can be referenced from outside the
package. Pure rename, no behavior change.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
Renames ApplySDNConfig/ApplyConfig/HasDpuNodes/TotalDPUs methods to
exported form and changes SetInput() to return *SystemTestInput
(previously void, only mutated the package-private 'input' global) so
external callers can obtain the constructed value directly.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
Fixes remaining references to ApplySDNConfig/ApplyConfig/HasDpuNodes/
TotalDPUs across the package (gopls rename call-site updates that
hadn't been staged yet) and a stale doc comment.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
…ntsInput fields

Both types were already exported but every field was unexported,
making them uninstantiable from outside the package. Exports the
remaining fields and getProvisionDPUClustersInput ->
GetProvisionDPUClustersInput, the only function that builds a
ProvisionDPUClustersInput from the current SystemTestInput.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
Exports the package-level shared state that non-test files read
directly instead of receiving as parameters: Ctx, TestClient,
RestConfig, Clientset, Conf, CleanupFlags, CleanupTracker,
ArtifactsDir, CollectResources, DPUClusterClient,
DPUClusterRestConfig, DPUClusterRestClient, HostClusterRESTClient,
MetricsURI. An external caller can now set these before invoking
Validate*/Verify* functions, matching the package's existing
global-state design. Vars only used within _test.go files
(configPath, testKubeconfig, externalTest, enableSOSReports,
dpuClusterClientsInitialized) are left unexported.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
Exports config -> Config (all fields were already exported, only the
type name was not) and readConfig -> ReadConfig. Exports the
namespace/name/timeout consts referenced when constructing objects
that match the suite's conventions: ConfigName,
DPFOperatorSystemNamespace, ArgoCDTrackingIDAnnotation,
NGCPullSecretName, DPFPullSecretName, KubeStateMetricsPort,
DefaultAPIServerPort, PerformanceMTU, ProvisioningTimeout,
DPUDeploymentReadyTimeout. testMTUValue is left unexported as it is
only used by test files exercising an MTU-change scenario.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
The VPCOVN scenario had no exported facade at all - its logic lived
entirely in vpcovn_test.go's It() blocks calling unexported helpers
in vpcovn.go directly. Exports VPCOVNTestInput and its 8 fields,
ApplyVPCOVNConfig, all 19 unexported helper functions
(CreateVtepDPUServiceIPAM, CreateOVNCentralDPUService,
CreateOrUpdateVPCDPUServiceChain, etc.), and the VPCOVNInput
package-var singleton so an external caller can reconstruct the same
scenario the upstream test drives.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
Same treatment as VPCOVN: the Weave scenario had no exported facade,
its logic lived entirely in weave_test.go's It() blocks calling
unexported helpers in weave.go directly. Exports WeaveTestInput and
its field, ApplyWeaveConfig, response/metric types
(VpcctlVNetResponse, VpcctlAttachmentResponse,
VpcctlListAttachmentResponse, WeaveMetrics, MetricDeltaExpect,
MetricRef) and their fields, all 24 unexported helper functions, and
the WeaveInput package-var singleton. weavePodsToVerify,
dpuPortToPCIUnderscored, and dpuPortToDropNIC are left unexported as
they are small lookup tables only referenced from within
weave_test.go's own test bodies, not needed to call any exported
helper.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
…est.go files

Go excludes _test.go files from normal package imports, so all the
work exporting SystemTestInput/globals/etc in prior commits was
necessary but not sufficient - the var declarations and setup
functions themselves lived in _test.go files and were simply
undefined for an external `import e2e ...` consumer.

Moves (pure relocation, no logic changes):
- Package vars Ctx/TestClient/RestConfig/Clientset/Conf/CleanupFlags/
  CleanupTracker/ArtifactsDir/CollectResources/input/VPCOVNInput and
  the test-flag-only externalTest var: e2e_suite_test.go and
  system_test.go -> new globals.go
- SetInput/SystemSetupBeforeSuite/createNGCImagePullSecret/
  AnnotateAndLabelNodes/GetProvisionDPUClustersInput/validateFlags:
  system_test.go -> new system_bootstrap.go
- ProvisioningBeforeSuite: provisioning_test.go -> provisioning.go
- SNAPBeforeSuite: snap_test.go -> new snap.go
- SDNBeforeSuite: sdn_test.go -> new sdn.go
- VPCOVNBeforeSuite: vpcovn_test.go -> vpcovn.go
- CreateDPUWorkerNodes: scale_test.go -> new scale.go

_test.go files keep only their Describe/It/BeforeSuite/AfterSuite
Ginkgo registrations and the TestE2E entrypoint, which only matter
when running via 'go test' - confirmed both 'go build ./...' (the
external-import path) and 'go test ./test/e2e/... -list .*' (the
internal go-test path) pass after this change.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
The upgrade validation framework (installPhase/validationPhase DSL,
artifact snapshot/compare machinery, BFB LTS rollout helpers) was
entirely defined in _test.go files with unexported identifiers -
neither visible nor reachable from an external import.

Renames upgrade_framework_test.go -> upgrade_framework.go and
upgrade_artifacts_test.go -> upgrade_artifacts.go outright (neither
file had any Describe/It registrations, only type/func/var
declarations). Splits the 3 helpers upgrade_framework.go depends on
(RolloutAllDPUs, VerifyDPUsHaveKubeletVersion,
RemoveStaleDPUDeviceProtectionFinalizers) out of upgrade_lts_test.go
into a new upgrade_lts.go, leaving that file's Describe block and its
two local-only helpers (expectedDPUServicesV2510, envOrDefault) in
place.

Exports InstallPhaseInput/ValidationPhaseInput and all their fields,
InstallPhase/ValidationPhase/IsUpgradeValidationPhase,
UpgradeExpectedChange and its fields, ValidationPhaseLabels, and the
remaining ~20 unexported helper functions across
upgrade_framework.go/upgrade_artifacts.go/upgrade_apply.go/
upgrade_lts.go. An external caller can now define and register a
custom InstallPhase/ValidationPhase the same way upgrade_test.go and
upgrade_lts_test.go's Describe blocks do.

Confirmed clean: go build ./... (external-import path), go vet ./...,
and go test ./test/e2e/... -list '.*' (internal go-test path).

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
…cturedFromFile, GetDPUClusterClient(s))

These utils.go/system_setup.go helpers are called throughout the
package to check Ginkgo label filters, load YAML manifests into
objects, and establish DPU cluster clients - all required to
replicate BeforeSuite/SetInput semantics from outside the package.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
Applies the same export treatment to leader_election.go's target type
that was proven in an earlier standalone PoC against the leader
election failover test, now folded into this branch's broader export
so the type is consistent with the rest of the exported surface.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
…ommit

The LeaderElectionTarget struct-literal fields and target.Component
reference in leader_election_test.go should have been included in
d241d5d alongside the type/field renames in leader_election.go.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
The quick-start guide still referenced the pre-export lowercase names
(systemTestInput, hasDpuNodes, applyConfig, ctx, dpuClusterClient,
input.client, dpfPullSecretName/dpfOperatorSystemNamespace) that this
branch renamed to their exported form. Updates all references and the
system_test.go -> system_bootstrap.go file pointer for SetInput/
SystemSetupBeforeSuite.

    gitleaks.version: 8.30.0
    gitleaks.check-secrets: ENABLED
@josecastillolema

Copy link
Copy Markdown
Author

cc @aserdean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant