Skip to content

chore(tests): Add YAML-driven integration test framework for sources#6158

Merged
k8s-ci-robot merged 18 commits intokubernetes-sigs:masterfrom
gofogo:chore-integration-tests-v0
Mar 16, 2026
Merged

chore(tests): Add YAML-driven integration test framework for sources#6158
k8s-ci-robot merged 18 commits intokubernetes-sigs:masterfrom
gofogo:chore-integration-tests-v0

Conversation

@ivankatliarchuk
Copy link
Copy Markdown
Member

@ivankatliarchuk ivankatliarchuk commented Jan 31, 2026

What does it do ?

I'm going to add more tests in follow-up, in this PR focus is on adding the testing framework.

Main challanges this should help to solve

  • we have multiple layers like

    • combination of multiple sources (this is currently not tested at all)
    • wrappers and post processors - on top of multiple sources
    • inconsistent values passed to providers
  • wrappers are going to play key role in future, especially when we remove most of the providers and keep only webhook. Most of the logic is going to be happening in service postprocessors -> and this combination service + service + wrapper + wrapper needs a testing framework

    • Scenario-based test framework using YAML configuration
    • Demonstrating pattern
      • Multieple sources with target filter
      • Multiple sources with deduplications
    • Auto-generation of dependent resources (Pods, EndpointSlices) from service definitions
      • Initial headless service test case demonstrating

The folder tests/integration/toolkit require revisit, theres are some duplicates, in follow-up I'll try to review designs to reduce duplicaiton

Motivation

At the moment we are testing in isolation: sources, wrapper. This approach misses the behavioral tests, when multiple sources with wrappers(processors,post-processors, deduplicates are enabled)

Unit tests for sources are scattered and require significant boilerplate to set up complex scenarios like headless services with pods and endpoint slices or multiple sources behaviour + wrappers to modify behaviour. A declarative approach simplifies adding new test cases.

Follow-up

  • add inmemory provider to have it trully end-2-end
  • Address // TODO: copied from controller/execute.go#buildSources. if the controller's buildSources logic changes, this copy diverges silently.
  • Duplicated helpers -> move them to shared location
  • more scenarios with current known limitations/bugs

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly

Use cases (in theory should help to prevent regressions)

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 31, 2026
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@ivankatliarchuk ivankatliarchuk force-pushed the chore-integration-tests-v0 branch from 2027d16 to ec8f6da Compare January 31, 2026 14:45
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 31, 2026

Pull Request Test Coverage Report for Build 23136525461

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-1.0%) to 78.192%

Files with Coverage Reduction New Missed Lines %
openshift_route.go 1 83.59%
Totals Coverage Status
Change from base Build 23136104975: -1.0%
Covered Lines: 16576
Relevant Lines: 21199

💛 - Coveralls

ivankatliarchuk and others added 4 commits February 1, 2026 00:11
* master:
  fix(annotations): initialize annotation keys at declaration time (kubernetes-sigs#6159)
  chore(linter): unused params and functions linter (kubernetes-sigs#6142)
  docs(fqdn): use correct arguments order in FQDN Templating custom functions (kubernetes-sigs#6144)
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
@ivankatliarchuk ivankatliarchuk force-pushed the chore-integration-tests-v0 branch 2 times, most recently from a2b815f to 6e3b7ae Compare March 1, 2026 16:57
@ivankatliarchuk ivankatliarchuk force-pushed the chore-integration-tests-v0 branch from 6e3b7ae to bb4fdc9 Compare March 1, 2026 17:00
@ivankatliarchuk
Copy link
Copy Markdown
Member Author

/test pull-external-dns-unit-test

Comment on lines +58 to +63
// Validate scenarios
for i, s := range scenarios.Scenarios {
if s.Description == "" {
return nil, fmt.Errorf("scenario %d (%q) is missing required field: description", i, s.Name)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only description is required?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added few more fields. I was thinking about adding github.com/go-playground/validator/v10. and

The struct tag approach would look like:
  type Scenario struct {
      Name        string `json:"name"        validate:"required"`
      Description string `json:"description" validate:"required"`
      Config      ScenarioConfig             `json:"config"`
      ...
  }

  And in LoadScenarios:
  validate := validator.New()
  for i, s := range scenarios.Scenarios {
      if err := validate.Struct(s); err != nil {
          return nil, fmt.Errorf("scenario %d (%q): %w", i, s.Name, err)
      }
  }

But for now probably overkill. Will see

Comment on lines +62 to +66
}
}

return &scenarios, nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to used file embedding, because editing the tests.yaml file does not invalidate the test cache, which then requires to run the test with go test -count=1.
Embedding it invalidates the cache when the file is modified.

Something like this:

package scenarios

import _ "embed"

//go:embed tests.yaml
var Tests []byte
    var testScenarios TestScenarios
	if err := yaml.Unmarshal(scenarios.Tests, &testScenarios); err != nil {
		return nil, err
	}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. Implemented

Comment on lines +50 to +54
args := m.Called()
if args.Error(1) != nil {
return nil, args.Error(1)
}
return args.Get(0).(gateway.Interface), nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a not implemented error as in RESTConfig()? Or an explicit panic?
It should panic at m.Called() since there is no .On().Return for this method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment is return nil, fmt.Errorf("RESTConfig: not implemented"). Basically, in real scenario is required, at the moment, we are using moscks directly. I simply have no use case at the moment.

@ivankatliarchuk ivankatliarchuk requested a review from vflaux March 16, 2026 09:25
@vflaux
Copy link
Copy Markdown
Contributor

vflaux commented Mar 16, 2026

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 16, 2026
@ivankatliarchuk
Copy link
Copy Markdown
Member Author

/approve

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ivankatliarchuk

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 16, 2026
@k8s-ci-robot k8s-ci-robot merged commit 3f42ce9 into kubernetes-sigs:master Mar 16, 2026
18 checks passed
@ivankatliarchuk ivankatliarchuk deleted the chore-integration-tests-v0 branch March 16, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. docs lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants