talos/internal/integration/base/base.go
Andrey Smirnov 0afd0f651b chore: provide provisioned cluster info to integration test
Integration test can optionally consume cluster state as generated by
the call to `osctl cluster create` and use it to discover nodes in
integration tests.

This means that now CLI tests can use that as discovery source, and
API/K8s tests by default as well.

Flat list of nodes is to be replaced by something more complex in the
next iteration, but it's good for this PR.

As a demo, add CLI test with multiple nodes (dmesg).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-01-31 18:21:30 +03:00

61 lines
1.8 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// +build integration
// Package base provides shared definition of base suites for tests
package base
import (
"github.com/talos-systems/talos/internal/pkg/provision"
)
// TalosSuite defines most common settings for integration test suites
type TalosSuite struct {
// Endpoint to use to connect, if not set config is used
Endpoint string
// K8sEndpoint is API server endpoint, if set overrides kubeconfig
K8sEndpoint string
// Cluster describes provisioned cluster, used for discovery purposes
Cluster provision.Cluster
// TalosConfig is a path to talosconfig
TalosConfig string
// Version is the (expected) version of Talos tests are running against
Version string
// OsctlPath is path to osctl binary
OsctlPath string
discoveredNodes []string
}
// DiscoverNodes provides basic functionality to discover cluster nodes via test settings.
//
// This method is overridden in specific suites to allow for specific discovery.
func (talosSuite *TalosSuite) DiscoverNodes() []string {
if talosSuite.discoveredNodes == nil {
if talosSuite.Cluster != nil {
for _, node := range talosSuite.Cluster.Info().Nodes {
talosSuite.discoveredNodes = append(talosSuite.discoveredNodes, node.PrivateIP.String())
}
}
}
return talosSuite.discoveredNodes
}
// ConfiguredSuite expects config to be set before running
type ConfiguredSuite interface {
SetConfig(config TalosSuite)
}
// SetConfig implements ConfiguredSuite
func (suite *TalosSuite) SetConfig(config TalosSuite) {
*suite = config
}
// NamedSuite interface provides names for test suites
type NamedSuite interface {
SuiteName() string
}