talos/internal/integration/cli/validate.go
Alexey Palazhchenko 3c1b32199d chore: refactor CLI tests
Use testing.T.TempDir.
Add support for `talosctl --endpoints`.

Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
2021-06-23 05:49:00 -07:00

67 lines
1.5 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 cli
import (
"fmt"
"os"
"github.com/talos-systems/talos/internal/integration/base"
)
// ValidateSuite verifies dmesg command.
type ValidateSuite struct {
base.CLISuite
tmpDir string
savedCwd string
}
// SuiteName ...
func (suite *ValidateSuite) SuiteName() string {
return "cli.ValidateSuite"
}
// SetupTest ...
func (suite *ValidateSuite) SetupTest() {
suite.tmpDir = suite.T().TempDir()
var err error
suite.savedCwd, err = os.Getwd()
suite.Require().NoError(err)
suite.Require().NoError(os.Chdir(suite.tmpDir))
}
// TearDownTest ...
func (suite *ValidateSuite) TearDownTest() {
if suite.savedCwd != "" {
suite.Require().NoError(os.Chdir(suite.savedCwd))
}
}
// TestValidate generates config and validates it for all the modes.
func (suite *ValidateSuite) TestValidate() {
suite.RunCLI([]string{"gen", "config", "foobar", "https://10.0.0.1"})
for _, configFile := range []string{"controlplane.yaml", "join.yaml"} {
configFile := configFile
for _, mode := range []string{"cloud", "container"} {
mode := mode
suite.Run(fmt.Sprintf("%s-%s", configFile, mode), func() {
suite.RunCLI([]string{"validate", "-m", mode, "-c", configFile, "--strict"})
})
}
}
}
func init() {
allSuites = append(allSuites, new(ValidateSuite))
}