mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-11 17:17:05 +02:00
This moves our test scripts to using the bootstrap API. Some automation around invoking the bootstrap API was also added to give the same ease of use when creating clusters with the CLI. Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
68 lines
1.8 KiB
Go
68 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_cli
|
|
|
|
package base
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"regexp"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/talos-systems/talos/pkg/retry"
|
|
)
|
|
|
|
// CLISuite is a base suite for CLI tests
|
|
type CLISuite struct {
|
|
suite.Suite
|
|
TalosSuite
|
|
}
|
|
|
|
// DiscoverNodes provides list of Talos nodes in the cluster.
|
|
//
|
|
// As there's no way to provide this functionality via Talos CLI, it relies on cluster info.
|
|
func (cliSuite *CLISuite) DiscoverNodes() []string {
|
|
discoveredNodes := cliSuite.TalosSuite.DiscoverNodes()
|
|
if discoveredNodes != nil {
|
|
return discoveredNodes
|
|
}
|
|
|
|
// still no nodes, skip the test
|
|
cliSuite.T().Skip("no nodes were discovered")
|
|
|
|
return nil
|
|
}
|
|
|
|
func (cliSuite *CLISuite) buildCLICmd(args []string) *exec.Cmd {
|
|
// TODO: add support for calling `talosctl config endpoint` before running talosctl
|
|
|
|
args = append([]string{"--talosconfig", cliSuite.TalosConfig}, args...)
|
|
|
|
return exec.Command(cliSuite.TalosctlPath, args...)
|
|
}
|
|
|
|
// RunCLI runs talosctl binary with the options provided
|
|
func (cliSuite *CLISuite) RunCLI(args []string, options ...RunOption) {
|
|
Run(&cliSuite.Suite, cliSuite.buildCLICmd(args), options...)
|
|
}
|
|
|
|
func (cliSuite *CLISuite) RunAndWaitForMatch(args []string, regex *regexp.Regexp, duration time.Duration, options ...retry.Option) {
|
|
cliSuite.Assert().NoError(retry.Constant(duration, options...).Retry(func() error {
|
|
stdout, _, err := RunAndWait(&cliSuite.Suite, cliSuite.buildCLICmd(args))
|
|
if err != nil {
|
|
return retry.UnexpectedError(err)
|
|
}
|
|
|
|
if !regex.MatchString(stdout.String()) {
|
|
return retry.ExpectedError(fmt.Errorf("stdout doesn't match: %q", stdout))
|
|
}
|
|
|
|
return nil
|
|
}))
|
|
}
|