Files
k3k/tests/framework/env/env.go
Enrico Candino ba1648e560 Refactoring of tests moving common logic in tests/framework (#769)
* first commit

* refactor: update golangci configuration and reorder imports in namespace.go

* refactor: update golangci configuration for linters and formatters

* check restart for logs fetch

* rverted a bit the structure

* requested changes

* WriteLogs rename
2026-04-13 12:50:38 +02:00

35 lines
1.1 KiB
Go

package env
import (
"path/filepath"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)
// Config holds the envtest environment configuration.
type Config struct {
CRDPaths []string
Scheme *runtime.Scheme
}
// NewEnvironment creates a new envtest.Environment with CRDs from the k3k charts directory.
// The scheme parameter should be created using the scheme package.
func NewEnvironment(scheme *runtime.Scheme) *envtest.Environment {
return &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "charts", "k3k", "templates", "crds")},
ErrorIfCRDPathMissing: true,
Scheme: scheme,
}
}
// NewEnvironmentWithPaths creates a new envtest.Environment with custom CRD paths.
// This is useful when running tests from different locations in the directory tree.
func NewEnvironmentWithPaths(scheme *runtime.Scheme, crdPaths ...string) *envtest.Environment {
return &envtest.Environment{
CRDDirectoryPaths: crdPaths,
ErrorIfCRDPathMissing: true,
Scheme: scheme,
}
}