mirror of
https://github.com/opentofu/opentofu.git
synced 2025-12-18 15:46:08 -05:00
Fix linting in internal/command (#2798)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
parent
8396d0459c
commit
aaed9f83e4
30 changed files with 234 additions and 137 deletions
|
|
@ -4,6 +4,9 @@
|
|||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
version: "2"
|
||||
issues:
|
||||
max-issues-per-linter: 0
|
||||
max-same-issues: 0
|
||||
linters:
|
||||
settings:
|
||||
staticcheck:
|
||||
|
|
|
|||
|
|
@ -322,6 +322,8 @@ func TestApply_parallelism(t *testing.T) {
|
|||
// called once we reach the desired concurrency, allowing all apply calls
|
||||
// to proceed in unison.
|
||||
beginCtx, begin := context.WithCancel(context.Background())
|
||||
// Ensure cancel is fired regardless of test
|
||||
defer begin()
|
||||
|
||||
// Since our mock provider has its own mutex preventing concurrent calls
|
||||
// to ApplyResourceChange, we need to use a number of separate providers
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import (
|
|||
func TestMetaCompletePredictWorkspaceName(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// make sure a vars file doesn't interfere
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ func loadConfigDir(path string) (*Config, tfdiags.Diagnostics) {
|
|||
// syntax errors, and our patterns are hard-coded here.
|
||||
hclMatched, _ := filepath.Match("*.tfrc", name)
|
||||
jsonMatched, _ := filepath.Match("*.tfrc.json", name)
|
||||
if !(hclMatched || jsonMatched) {
|
||||
if !hclMatched && !jsonMatched {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,12 +71,20 @@ func (s *LocalState) WriteState(state *tofu.State) error {
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
err := s.writeState(state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Sync after write
|
||||
return s.stateFileOut.Sync()
|
||||
}
|
||||
func (s *LocalState) writeState(state *tofu.State) error {
|
||||
if s.stateFileOut == nil {
|
||||
if err := s.createStateFiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer s.stateFileOut.Sync()
|
||||
|
||||
s.state = state.DeepCopy() // don't want mutations before we actually get this written to disk
|
||||
|
||||
|
|
@ -160,7 +168,9 @@ func (s *LocalState) RefreshState() error {
|
|||
}
|
||||
|
||||
// we have a state file, make sure we're at the start
|
||||
s.stateFileOut.Seek(0, io.SeekStart)
|
||||
if _, err := s.stateFileOut.Seek(0, io.SeekStart); err != nil {
|
||||
return err
|
||||
}
|
||||
reader = s.stateFileOut
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -587,7 +587,9 @@ func testStdinPipe(t *testing.T, src io.Reader) func() {
|
|||
// Copy the data from the reader to the pipe
|
||||
go func() {
|
||||
defer w.Close()
|
||||
io.Copy(w, src)
|
||||
if _, err := io.Copy(w, src); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return func() {
|
||||
|
|
@ -618,14 +620,21 @@ func testStdoutCapture(t *testing.T, dst io.Writer) func() {
|
|||
doneCh := make(chan struct{})
|
||||
go func() {
|
||||
defer close(doneCh)
|
||||
defer r.Close()
|
||||
io.Copy(dst, r)
|
||||
if _, err := io.Copy(dst, r); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := r.Close(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
return func() {
|
||||
// Close the writer end of the pipe
|
||||
w.Sync()
|
||||
w.Close()
|
||||
// This test code is racey
|
||||
_ = w.Sync()
|
||||
if err := w.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Reset stdout
|
||||
os.Stdout = old
|
||||
|
|
@ -720,7 +729,9 @@ func testBackendState(t *testing.T, s *states.State, c int) (*legacy.State, *htt
|
|||
}
|
||||
|
||||
resp.Header().Set("Content-MD5", b64md5)
|
||||
resp.Write(buf.Bytes())
|
||||
if _, err := resp.Write(buf.Bytes()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// If a state was given, make sure we calculate the proper b64md5
|
||||
|
|
@ -777,7 +788,9 @@ func testRemoteState(t *testing.T, s *states.State, c int) (*legacy.State, *http
|
|||
}
|
||||
|
||||
resp.Header().Set("Content-MD5", b64md5)
|
||||
resp.Write(buf.Bytes())
|
||||
if _, err := resp.Write(buf.Bytes()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
retState := legacy.NewState()
|
||||
|
|
@ -786,7 +799,7 @@ func testRemoteState(t *testing.T, s *states.State, c int) (*legacy.State, *http
|
|||
b := &legacy.BackendState{
|
||||
Type: "http",
|
||||
}
|
||||
b.SetConfig(cty.ObjectVal(map[string]cty.Value{
|
||||
if err := b.SetConfig(cty.ObjectVal(map[string]cty.Value{
|
||||
"address": cty.StringVal(srv.URL),
|
||||
}), &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
|
@ -795,7 +808,9 @@ func testRemoteState(t *testing.T, s *states.State, c int) (*legacy.State, *http
|
|||
Required: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
retState.Backend = b
|
||||
|
||||
if s != nil {
|
||||
|
|
@ -841,8 +856,13 @@ func testLockState(t *testing.T, sourceDir, path string) (func(), error) {
|
|||
return nil, err
|
||||
}
|
||||
deferFunc := func() {
|
||||
locker.Process.Signal(syscall.SIGTERM)
|
||||
locker.Wait()
|
||||
if err := locker.Process.Signal(syscall.SIGTERM); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Assume the sigterm above succeeds. The error here may represent
|
||||
// the signal sent above, but is difficult to check in a platform
|
||||
// agostic way
|
||||
_ = locker.Wait()
|
||||
}
|
||||
|
||||
// wait for the process to lock
|
||||
|
|
@ -992,9 +1012,15 @@ func testRegistrySource(t *testing.T) (source *getproviders.RegistrySource, clea
|
|||
func fakeRegistryHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
path := req.URL.EscapedPath()
|
||||
|
||||
write := func(data string) {
|
||||
if _, err := resp.Write([]byte(data)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(path, "/providers/v1/") {
|
||||
resp.WriteHeader(404)
|
||||
resp.Write([]byte(`not a provider registry endpoint`))
|
||||
write(`not a provider registry endpoint`)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1002,13 +1028,13 @@ func fakeRegistryHandler(resp http.ResponseWriter, req *http.Request) {
|
|||
|
||||
if len(pathParts) != 3 {
|
||||
resp.WriteHeader(404)
|
||||
resp.Write([]byte(`unrecognized path scheme`))
|
||||
write(`unrecognized path scheme`)
|
||||
return
|
||||
}
|
||||
|
||||
if pathParts[2] != "versions" {
|
||||
resp.WriteHeader(404)
|
||||
resp.Write([]byte(`this registry only supports legacy namespace lookup requests`))
|
||||
write(`this registry only supports legacy namespace lookup requests`)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1020,13 +1046,13 @@ func fakeRegistryHandler(resp http.ResponseWriter, req *http.Request) {
|
|||
resp.Header().Set("Content-Type", "application/json")
|
||||
resp.WriteHeader(200)
|
||||
if movedNamespace, ok := movedProviderNamespaces[name]; ok {
|
||||
resp.Write([]byte(fmt.Sprintf(`{"id":"%s/%s","moved_to":"%s/%s","versions":[{"version":"1.0.0","protocols":["4"]}]}`, namespace, name, movedNamespace, name)))
|
||||
fmt.Fprintf(resp, `{"id":"%s/%s","moved_to":"%s/%s","versions":[{"version":"1.0.0","protocols":["4"]}]}`, namespace, name, movedNamespace, name)
|
||||
} else {
|
||||
resp.Write([]byte(fmt.Sprintf(`{"id":"%s/%s","versions":[{"version":"1.0.0","protocols":["4"]}]}`, namespace, name)))
|
||||
fmt.Fprintf(resp, `{"id":"%s/%s","versions":[{"version":"1.0.0","protocols":["4"]}]}`, namespace, name)
|
||||
}
|
||||
} else {
|
||||
resp.WriteHeader(404)
|
||||
resp.Write([]byte(`provider not found`))
|
||||
write(`provider not found`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -1035,10 +1061,10 @@ func fakeRegistryHandler(resp http.ResponseWriter, req *http.Request) {
|
|||
if namespace, ok := movedProviderNamespaces[name]; ok && pathParts[0] == namespace {
|
||||
resp.Header().Set("Content-Type", "application/json")
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"id":"%s/%s","versions":[{"version":"1.0.0","protocols":["4"]}]}`, namespace, name)))
|
||||
fmt.Fprintf(resp, `{"id":"%s/%s","versions":[{"version":"1.0.0","protocols":["4"]}]}`, namespace, name)
|
||||
} else {
|
||||
resp.WriteHeader(404)
|
||||
resp.Write([]byte(`provider not found`))
|
||||
write(`provider not found`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package command
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
|
@ -102,7 +103,9 @@ func (c *FmtCommand) Run(args []string) int {
|
|||
buf := output.(*bytes.Buffer)
|
||||
ok := buf.Len() == 0
|
||||
if list {
|
||||
io.Copy(&cli.UiWriter{Ui: c.Ui}, buf)
|
||||
if _, err := io.Copy(&cli.UiWriter{Ui: c.Ui}, buf); err != nil {
|
||||
log.Printf("[ERROR] Unable to write UI output: %s", err)
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
return 0
|
||||
|
|
@ -215,7 +218,9 @@ func (c *FmtCommand) processFile(path string, r io.Reader, w io.Writer, isStdout
|
|||
diags = diags.Append(fmt.Errorf("Failed to generate diff for %s: %w", path, err))
|
||||
return diags
|
||||
}
|
||||
w.Write(diff)
|
||||
if _, err := w.Write(diff); err != nil {
|
||||
return diags.Append(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -407,7 +412,7 @@ func (c *FmtCommand) formatValueExpr(tokens hclwrite.Tokens) hclwrite.Tokens {
|
|||
hasTrailingParen = true
|
||||
}
|
||||
}
|
||||
if isMultiLine && !(hasLeadingParen && hasTrailingParen) {
|
||||
if isMultiLine && (!hasLeadingParen || !hasTrailingParen) {
|
||||
wrapped := make(hclwrite.Tokens, 0, len(trimmed)+2)
|
||||
wrapped = append(wrapped, &hclwrite.Token{
|
||||
Type: hclsyntax.TokenOParen,
|
||||
|
|
@ -591,29 +596,32 @@ func (c *FmtCommand) Synopsis() string {
|
|||
return "Reformat your configuration in the standard style"
|
||||
}
|
||||
|
||||
func withTempFile(b []byte, fn func(*os.File) error) error {
|
||||
f, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = f.Write(b)
|
||||
if err == nil {
|
||||
err = fn(f)
|
||||
}
|
||||
err = errors.Join(err, f.Close())
|
||||
err = errors.Join(err, os.Remove(f.Name()))
|
||||
return err
|
||||
}
|
||||
|
||||
func bytesDiff(b1, b2 []byte, path string) (data []byte, err error) {
|
||||
f1, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.Remove(f1.Name())
|
||||
defer f1.Close()
|
||||
err = withTempFile(b1, func(f1 *os.File) error {
|
||||
return withTempFile(b2, func(f2 *os.File) error {
|
||||
data, err = exec.Command("diff", "--label=old/"+path, "--label=new/"+path, "-u", f1.Name(), f2.Name()).CombinedOutput()
|
||||
if len(data) > 0 {
|
||||
// diff exits with a non-zero status when the files don't match.
|
||||
// Ignore that failure as long as we get output.
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
})
|
||||
})
|
||||
|
||||
f2, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.Remove(f2.Name())
|
||||
defer f2.Close()
|
||||
|
||||
f1.Write(b1)
|
||||
f2.Write(b2)
|
||||
|
||||
data, err = exec.Command("diff", "--label=old/"+path, "--label=new/"+path, "-u", f1.Name(), f2.Name()).CombinedOutput()
|
||||
if len(data) > 0 {
|
||||
// diff exits with a non-zero status when the files don't match.
|
||||
// Ignore that failure as long as we get output.
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -86,7 +85,6 @@ func TestGraph_noArgs(t *testing.T) {
|
|||
|
||||
func TestGraph_noConfig(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
|
|
|
|||
|
|
@ -309,7 +309,9 @@ func TestImport_initializationErrorShouldUnlock(t *testing.T) {
|
|||
}
|
||||
|
||||
// overwrite the config with one including a resource from an invalid provider
|
||||
copy.CopyFile(filepath.Join(testFixturePath("import-provider-invalid"), "main.tf"), filepath.Join(td, "main.tf"))
|
||||
if err := copy.CopyFile(filepath.Join(testFixturePath("import-provider-invalid"), "main.tf"), filepath.Join(td, "main.tf")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := testProvider()
|
||||
ui = new(cli.MockUi)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import (
|
|||
func TestInit_empty(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
|
|
@ -61,7 +60,6 @@ func TestInit_empty(t *testing.T) {
|
|||
func TestInit_multipleArgs(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
|
|
@ -86,7 +84,6 @@ func TestInit_multipleArgs(t *testing.T) {
|
|||
func TestInit_fromModule_cwdDest(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, os.ModePerm)
|
||||
t.Chdir(td)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
|
|
@ -436,7 +433,7 @@ func TestInit_backendConfigFile(t *testing.T) {
|
|||
},
|
||||
}
|
||||
flagConfigExtra := newRawFlags("-backend-config")
|
||||
flagConfigExtra.Set("input.config")
|
||||
_ = flagConfigExtra.Set("input.config")
|
||||
_, diags := c.backendConfigOverrideBody(flagConfigExtra, schema)
|
||||
if len(diags) != 0 {
|
||||
t.Errorf("expected no diags, got: %s", diags.Err())
|
||||
|
|
@ -2187,7 +2184,11 @@ func TestInit_providerLockFile(t *testing.T) {
|
|||
td := t.TempDir()
|
||||
testCopyDir(t, testFixturePath("init-provider-lock-file"), td)
|
||||
// The temporary directory does not have write permission (dr-xr-xr-x) after the copy
|
||||
defer os.Chmod(td, os.ModePerm)
|
||||
defer func() {
|
||||
if err := os.Chmod(td, os.ModePerm); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
t.Chdir(td)
|
||||
|
||||
providerSource, close := newMockProviderSource(t, map[string][]string{
|
||||
|
|
@ -2240,7 +2241,9 @@ provider "registry.opentofu.org/hashicorp/test" {
|
|||
|
||||
// Make the local directory read-only, and verify that rerunning init
|
||||
// succeeds, to ensure that we don't try to rewrite an unchanged lock file
|
||||
os.Chmod(".", 0555)
|
||||
if err := os.Chmod(".", 0555); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,13 +62,13 @@ func renderPrimitiveValue(value interface{}, t cty.Type, opts computed.RenderHum
|
|||
return opts.Colorize.Color("[dark_gray]null[reset]")
|
||||
}
|
||||
|
||||
switch {
|
||||
case t == cty.Bool:
|
||||
switch t {
|
||||
case cty.Bool:
|
||||
if value.(bool) {
|
||||
return "true"
|
||||
}
|
||||
return "false"
|
||||
case t == cty.Number:
|
||||
case cty.Number:
|
||||
num := value.(json.Number)
|
||||
return num.String()
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -58,11 +58,12 @@ func Marshal(f map[string]function.Function) ([]byte, tfdiags.Diagnostics) {
|
|||
signatures := newFunctions()
|
||||
|
||||
for name, v := range f {
|
||||
if name == "can" || name == lang.CoreNamespace+"can" {
|
||||
switch name {
|
||||
case "can", lang.CoreNamespace + "can":
|
||||
signatures.Signatures[name] = marshalCan(v)
|
||||
} else if name == "try" || name == lang.CoreNamespace+"try" {
|
||||
case "try", lang.CoreNamespace + "try":
|
||||
signatures.Signatures[name] = marshalTry(v)
|
||||
} else {
|
||||
default:
|
||||
signature, err := marshalFunction(v)
|
||||
if err != nil {
|
||||
diags = diags.Append(tfdiags.Sourceless(
|
||||
|
|
|
|||
|
|
@ -828,22 +828,22 @@ func unknownAsBool(val cty.Value) cty.Value {
|
|||
}
|
||||
|
||||
func actionString(action string) []string {
|
||||
switch {
|
||||
case action == "NoOp":
|
||||
switch action {
|
||||
case "NoOp":
|
||||
return []string{"no-op"}
|
||||
case action == "Create":
|
||||
case "Create":
|
||||
return []string{"create"}
|
||||
case action == "Delete":
|
||||
case "Delete":
|
||||
return []string{"delete"}
|
||||
case action == "Update":
|
||||
case "Update":
|
||||
return []string{"update"}
|
||||
case action == "CreateThenDelete":
|
||||
case "CreateThenDelete":
|
||||
return []string{"create", "delete"}
|
||||
case action == "Read":
|
||||
case "Read":
|
||||
return []string{"read"}
|
||||
case action == "DeleteThenCreate":
|
||||
case "DeleteThenCreate":
|
||||
return []string{"delete", "create"}
|
||||
case action == "Forget":
|
||||
case "Forget":
|
||||
return []string{"forget"}
|
||||
default:
|
||||
return []string{action}
|
||||
|
|
|
|||
|
|
@ -277,7 +277,11 @@ func (c *LoginCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
json.Unmarshal(body, &motd)
|
||||
if err := json.Unmarshal(body, &motd); err != nil {
|
||||
c.logMOTDError(fmt.Errorf("platform responded with invalid motd payload: %w", err))
|
||||
c.outputDefaultTFCLoginSuccess()
|
||||
return 0
|
||||
}
|
||||
|
||||
if motd.Errors == nil && motd.Message != "" {
|
||||
c.Ui.Output(
|
||||
|
|
@ -453,7 +457,10 @@ func (c *LoginCommand) interactiveGetTokenByCode(ctx context.Context, hostname s
|
|||
|
||||
resp.Header().Add("Content-Type", "text/html")
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte(callbackSuccessMessage))
|
||||
if _, err := resp.Write([]byte(callbackSuccessMessage)); err != nil {
|
||||
log.Printf("[ERROR] login: cannot write response: %s", err)
|
||||
return
|
||||
}
|
||||
}),
|
||||
}
|
||||
panicHandler := logging.PanicHandlerWithTraceFn()
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ func (c *LogoutCommand) Help() string {
|
|||
defaultFile = "~/.terraform/credentials.tfrc.json"
|
||||
}
|
||||
|
||||
helpText := `
|
||||
helpText := fmt.Sprintf(`
|
||||
Usage: tofu [global options] logout [hostname]
|
||||
|
||||
Removes locally-stored credentials for specified hostname.
|
||||
|
|
@ -138,7 +138,7 @@ Usage: tofu [global options] logout [hostname]
|
|||
Note: the API token is only removed from local storage, not destroyed on the
|
||||
remote server, so it will remain valid until manually revoked.
|
||||
%s
|
||||
`
|
||||
`, defaultFile)
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -254,7 +254,9 @@ func (m *Meta) backendMigrateState_S_s(ctx context.Context, opts *backendMigrate
|
|||
opts.sourceWorkspace = currentWorkspace
|
||||
|
||||
// now switch back to the default env so we can access the new backend
|
||||
m.SetWorkspace(backend.DefaultStateName)
|
||||
if err := m.SetWorkspace(backend.DefaultStateName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.backendMigrateState_s_s(ctx, opts)
|
||||
}
|
||||
|
|
@ -738,7 +740,7 @@ func (m *Meta) backendMigrateState_S_TFC(ctx context.Context, opts *backendMigra
|
|||
// this has to be done before setting destinationWorkspace
|
||||
name = newName
|
||||
}
|
||||
opts.destinationWorkspace = strings.Replace(pattern, "*", name, -1)
|
||||
opts.destinationWorkspace = strings.ReplaceAll(pattern, "*", name)
|
||||
|
||||
// Force it, we confirmed above
|
||||
opts.force = true
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import (
|
|||
func TestMetaBackend_emptyDir(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// Get the backend
|
||||
|
|
@ -54,7 +53,9 @@ func TestMetaBackend_emptyDir(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
s.WriteState(testState())
|
||||
if err := s.WriteState(testState()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -94,7 +95,6 @@ func isEmptyState(path string) bool {
|
|||
func TestMetaBackend_emptyWithDefaultState(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// Write the legacy state
|
||||
|
|
@ -143,7 +143,9 @@ func TestMetaBackend_emptyWithDefaultState(t *testing.T) {
|
|||
// Write some state
|
||||
next := testState()
|
||||
next.RootModule().SetOutputValue("foo", cty.StringVal("bar"), false, "")
|
||||
s.WriteState(next)
|
||||
if err := s.WriteState(next); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -158,12 +160,10 @@ func TestMetaBackend_emptyWithDefaultState(t *testing.T) {
|
|||
func TestMetaBackend_emptyWithExplicitState(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// Create another directory to store our state
|
||||
stateDir := t.TempDir()
|
||||
os.MkdirAll(stateDir, 0755)
|
||||
|
||||
// Write the legacy state
|
||||
statePath := filepath.Join(stateDir, "foo")
|
||||
|
|
@ -214,7 +214,9 @@ func TestMetaBackend_emptyWithExplicitState(t *testing.T) {
|
|||
// Write some state
|
||||
next := testState()
|
||||
markStateForMatching(next, "bar") // just any change so it shows as different than before
|
||||
s.WriteState(next)
|
||||
if err := s.WriteState(next); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -274,7 +276,9 @@ func TestMetaBackend_configureNew(t *testing.T) {
|
|||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -514,7 +518,9 @@ func TestMetaBackend_configureNewWithStateExisting(t *testing.T) {
|
|||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -585,7 +591,9 @@ func TestMetaBackend_configureNewWithStateExistingNoMigrate(t *testing.T) {
|
|||
// Write some state
|
||||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -850,7 +858,9 @@ func TestMetaBackend_configuredChange(t *testing.T) {
|
|||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -1603,7 +1613,9 @@ func TestMetaBackend_configuredUnset(t *testing.T) {
|
|||
}
|
||||
|
||||
// Write some state
|
||||
s.WriteState(testState())
|
||||
if err := s.WriteState(testState()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -1661,7 +1673,9 @@ func TestMetaBackend_configuredUnsetCopy(t *testing.T) {
|
|||
}
|
||||
|
||||
// Write some state
|
||||
s.WriteState(testState())
|
||||
if err := s.WriteState(testState()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -1740,7 +1754,9 @@ func TestMetaBackend_planLocal(t *testing.T) {
|
|||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -1841,7 +1857,9 @@ func TestMetaBackend_planLocalStatePath(t *testing.T) {
|
|||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
@ -1928,7 +1946,9 @@ func TestMetaBackend_planLocalMatch(t *testing.T) {
|
|||
state = states.NewState()
|
||||
mark := markStateForMatching(state, "changing")
|
||||
|
||||
s.WriteState(state)
|
||||
if err := s.WriteState(state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.PersistState(nil); err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,7 +185,6 @@ func TestMeta_initStatePaths(t *testing.T) {
|
|||
|
||||
func TestMeta_Env(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
m := new(Meta)
|
||||
|
|
@ -256,7 +255,6 @@ func TestMeta_Workspace_override(t *testing.T) {
|
|||
|
||||
func TestMeta_Workspace_invalidSelected(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// this is an invalid workspace name
|
||||
|
|
|
|||
|
|
@ -677,7 +677,9 @@ func TestPlan_stateDefault(t *testing.T) {
|
|||
// Generate state and move it to the default path
|
||||
originalState := testState()
|
||||
statePath := testStateFile(t, originalState)
|
||||
os.Rename(statePath, path.Join(td, "terraform.tfstate"))
|
||||
if err := os.Rename(statePath, path.Join(td, "terraform.tfstate")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := planFixtureProvider()
|
||||
view, done := testView(t)
|
||||
|
|
@ -1345,7 +1347,7 @@ func TestPlan_init_required(t *testing.T) {
|
|||
t.Fatalf("expected error, got success")
|
||||
}
|
||||
got := output.Stderr()
|
||||
if !(strings.Contains(got, "tofu init") && strings.Contains(got, "provider registry.opentofu.org/hashicorp/test: required by this configuration but no version is selected")) {
|
||||
if !strings.Contains(got, "tofu init") || !strings.Contains(got, "provider registry.opentofu.org/hashicorp/test: required by this configuration but no version is selected") {
|
||||
t.Fatal("wrong error message in output:", got)
|
||||
}
|
||||
}
|
||||
|
|
@ -1613,6 +1615,8 @@ func TestPlan_parallelism(t *testing.T) {
|
|||
// called once we reach the desired concurrency, allowing all apply calls
|
||||
// to proceed in unison.
|
||||
beginCtx, begin := context.WithCancel(context.Background())
|
||||
// Ensure cancel is fired regardless of test
|
||||
defer begin()
|
||||
|
||||
// Since our mock provider has its own mutex preventing concurrent calls
|
||||
// to ApplyResourceChange, we need to use a number of separate providers
|
||||
|
|
|
|||
|
|
@ -85,7 +85,9 @@ func TestProvidersSchema_output(t *testing.T) {
|
|||
var got, want providerSchemas
|
||||
|
||||
gotString := ui.OutputWriter.String()
|
||||
json.Unmarshal([]byte(gotString), &got)
|
||||
if err := json.Unmarshal([]byte(gotString), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wantFile, err := os.Open("output.json")
|
||||
if err != nil {
|
||||
|
|
@ -96,7 +98,9 @@ func TestProvidersSchema_output(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
json.Unmarshal([]byte(byteValue), &want)
|
||||
if err := json.Unmarshal([]byte(byteValue), &want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !cmp.Equal(got, want) {
|
||||
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want))
|
||||
|
|
|
|||
|
|
@ -595,7 +595,9 @@ func TestShow_json_output(t *testing.T) {
|
|||
}
|
||||
|
||||
var want plan
|
||||
json.Unmarshal([]byte(byteValue), &want)
|
||||
if err := json.Unmarshal([]byte(byteValue), &want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// plan
|
||||
planView, planDone := testView(t)
|
||||
|
|
@ -651,7 +653,9 @@ func TestShow_json_output(t *testing.T) {
|
|||
var got plan
|
||||
|
||||
gotString := showOutput.Stdout()
|
||||
json.Unmarshal([]byte(gotString), &got)
|
||||
if err := json.Unmarshal([]byte(gotString), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Disregard format version to reduce needless test fixture churn
|
||||
want.FormatVersion = got.FormatVersion
|
||||
|
|
@ -733,7 +737,9 @@ func TestShow_json_output_sensitive(t *testing.T) {
|
|||
var got, want plan
|
||||
|
||||
gotString := showOutput.Stdout()
|
||||
json.Unmarshal([]byte(gotString), &got)
|
||||
if err := json.Unmarshal([]byte(gotString), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wantFile, err := os.Open("output.json")
|
||||
if err != nil {
|
||||
|
|
@ -744,7 +750,9 @@ func TestShow_json_output_sensitive(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected err: %s", err)
|
||||
}
|
||||
json.Unmarshal([]byte(byteValue), &want)
|
||||
if err := json.Unmarshal([]byte(byteValue), &want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Disregard format version to reduce needless test fixture churn
|
||||
want.FormatVersion = got.FormatVersion
|
||||
|
|
@ -829,7 +837,9 @@ func TestShow_json_output_conditions_refresh_only(t *testing.T) {
|
|||
var got, want plan
|
||||
|
||||
gotString := showOutput.Stdout()
|
||||
json.Unmarshal([]byte(gotString), &got)
|
||||
if err := json.Unmarshal([]byte(gotString), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wantFile, err := os.Open("output-refresh-only.json")
|
||||
if err != nil {
|
||||
|
|
@ -840,7 +850,9 @@ func TestShow_json_output_conditions_refresh_only(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected err: %s", err)
|
||||
}
|
||||
json.Unmarshal([]byte(byteValue), &want)
|
||||
if err := json.Unmarshal([]byte(byteValue), &want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Disregard format version to reduce needless test fixture churn
|
||||
want.FormatVersion = got.FormatVersion
|
||||
|
|
@ -930,7 +942,9 @@ func TestShow_json_output_state(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("unexpected err: %s", err)
|
||||
}
|
||||
json.Unmarshal([]byte(byteValue), &want)
|
||||
if err := json.Unmarshal([]byte(byteValue), &want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !cmp.Equal(got, want) {
|
||||
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want))
|
||||
|
|
|
|||
|
|
@ -292,7 +292,9 @@ func TestTaint_defaultWorkspaceState(t *testing.T) {
|
|||
ui := new(cli.MockUi)
|
||||
view, _ := testView(t)
|
||||
meta := Meta{Ui: ui, View: view}
|
||||
meta.SetWorkspace(testWorkspace)
|
||||
if err := meta.SetWorkspace(testWorkspace); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &TaintCommand{
|
||||
Meta: meta,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import (
|
|||
// doesn't fail.
|
||||
func TestUnlock(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// Write the legacy state
|
||||
|
|
|
|||
|
|
@ -316,7 +316,9 @@ func TestUntaint_defaultWorkspaceState(t *testing.T) {
|
|||
ui := new(cli.MockUi)
|
||||
view, _ := testView(t)
|
||||
meta := Meta{Ui: ui, View: view}
|
||||
meta.SetWorkspace(testWorkspace)
|
||||
if err := meta.SetWorkspace(testWorkspace); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c := &UntaintCommand{
|
||||
Meta: meta,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func TestCountHookPostDiff_DestroyDeposed(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.DeposedKey("deadbeef"), plans.Delete, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.DeposedKey("deadbeef"), plans.Delete, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -68,7 +68,7 @@ func TestCountHookPostDiff_DestroyOnly(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.CurrentGen, plans.Delete, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.CurrentGen, plans.Delete, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -110,7 +110,7 @@ func TestCountHookPostDiff_AddOnly(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.CurrentGen, plans.Create, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.CurrentGen, plans.Create, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -155,7 +155,7 @@ func TestCountHookPostDiff_ChangeOnly(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.CurrentGen, plans.Update, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.CurrentGen, plans.Update, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -186,7 +186,7 @@ func TestCountHookPostDiff_Mixed(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.CurrentGen, a, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.CurrentGen, a, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -218,7 +218,7 @@ func TestCountHookPostDiff_NoChange(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.CurrentGen, plans.NoOp, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.CurrentGen, plans.NoOp, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -250,7 +250,7 @@ func TestCountHookPostDiff_DataSource(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PostDiff(addr, states.CurrentGen, a, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostDiff(addr, states.CurrentGen, a, cty.DynamicVal, cty.DynamicVal)
|
||||
}
|
||||
|
||||
expected := new(countHook)
|
||||
|
|
@ -296,8 +296,8 @@ func TestCountHookApply_ChangeOnly(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PreApply(addr, states.CurrentGen, plans.Update, cty.DynamicVal, cty.DynamicVal)
|
||||
h.PostApply(addr, states.CurrentGen, cty.DynamicVal, nil)
|
||||
_, _ = h.PreApply(addr, states.CurrentGen, plans.Update, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostApply(addr, states.CurrentGen, cty.DynamicVal, nil)
|
||||
}
|
||||
|
||||
expected := &countHook{pending: make(map[string]plans.Action)}
|
||||
|
|
@ -327,8 +327,8 @@ func TestCountHookApply_DestroyOnly(t *testing.T) {
|
|||
Name: k,
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance)
|
||||
|
||||
h.PreApply(addr, states.CurrentGen, plans.Delete, cty.DynamicVal, cty.DynamicVal)
|
||||
h.PostApply(addr, states.CurrentGen, cty.DynamicVal, nil)
|
||||
_, _ = h.PreApply(addr, states.CurrentGen, plans.Delete, cty.DynamicVal, cty.DynamicVal)
|
||||
_, _ = h.PostApply(addr, states.CurrentGen, cty.DynamicVal, nil)
|
||||
}
|
||||
|
||||
expected := &countHook{pending: make(map[string]plans.Action)}
|
||||
|
|
|
|||
|
|
@ -86,12 +86,12 @@ func (v *OutputHuman) Output(name string, outputs map[string]*states.OutputValue
|
|||
for _, k := range ks {
|
||||
vs := outputs[k]
|
||||
if vs.Sensitive && !v.view.showSensitive {
|
||||
outputBuf.WriteString(fmt.Sprintf("%s = <sensitive>\n", k))
|
||||
fmt.Fprintf(outputBuf, "%s = <sensitive>\n", k)
|
||||
continue
|
||||
}
|
||||
|
||||
result := repl.FormatValue(vs.Value, 0)
|
||||
outputBuf.WriteString(fmt.Sprintf("%s = %s\n", k, result))
|
||||
fmt.Fprintf(outputBuf, "%s = %s\n", k, result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -394,7 +394,7 @@ func (t *TestJSON) File(file *moduletest.File) {
|
|||
t.view.log.Info(
|
||||
fmt.Sprintf("%s... %s", file.Name, testStatus(file.Status)),
|
||||
"type", json.MessageTestFile,
|
||||
json.MessageTestFile, json.TestFileStatus{file.Name, json.ToTestStatus(file.Status)},
|
||||
json.MessageTestFile, json.TestFileStatus{Path: file.Name, Status: json.ToTestStatus(file.Status)},
|
||||
"@testfile", file.Name)
|
||||
t.Diagnostics(nil, file, file.Diagnostics)
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ func (t *TestJSON) Run(run *moduletest.Run, file *moduletest.File) {
|
|||
t.view.log.Info(
|
||||
fmt.Sprintf(" %q... %s", run.Name, testStatus(run.Status)),
|
||||
"type", json.MessageTestRun,
|
||||
json.MessageTestRun, json.TestRunStatus{file.Name, run.Name, json.ToTestStatus(run.Status)},
|
||||
json.MessageTestRun, json.TestRunStatus{Path: file.Name, Run: run.Name, Status: json.ToTestStatus(run.Status)},
|
||||
"@testfile", file.Name,
|
||||
"@testrun", run.Name)
|
||||
|
||||
|
|
|
|||
|
|
@ -3526,7 +3526,8 @@ func runTestSaveErroredStateFile(t *testing.T, tc map[string]struct {
|
|||
|
||||
streams, done := terminal.StreamsForTesting(t)
|
||||
|
||||
if viewType == arguments.ViewHuman {
|
||||
switch viewType {
|
||||
case arguments.ViewHuman:
|
||||
view := NewTest(arguments.ViewHuman, NewView(streams))
|
||||
SaveErroredTestStateFile(data.state, data.run, data.file, view)
|
||||
output := done(t)
|
||||
|
|
@ -3535,7 +3536,7 @@ func runTestSaveErroredStateFile(t *testing.T, tc map[string]struct {
|
|||
if diff := cmp.Diff(expected, actual); len(diff) > 0 {
|
||||
t.Errorf("expected:\n%s\nactual:\n%s\ndiff:\n%s", expected, actual, diff)
|
||||
}
|
||||
} else if viewType == arguments.ViewJSON {
|
||||
case arguments.ViewJSON:
|
||||
view := NewTest(arguments.ViewJSON, NewView(streams))
|
||||
SaveErroredTestStateFile(data.state, data.run, data.file, view)
|
||||
want, ok := data.want.([]map[string]interface{})
|
||||
|
|
@ -3543,7 +3544,7 @@ func runTestSaveErroredStateFile(t *testing.T, tc map[string]struct {
|
|||
t.Fatalf("Failed to assert want as []map[string]interface{}")
|
||||
}
|
||||
testJSONViewOutputEquals(t, done(t).All(), want)
|
||||
} else {
|
||||
default:
|
||||
t.Fatalf("Unsupported view type: %v", viewType)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func (d *Dir) SetForcedPluginDirs(dirs []string) error {
|
|||
// the directory then we'll fail to create the file below too,
|
||||
// and that subsequent error will more directly reflect what we
|
||||
// are trying to do here.
|
||||
d.ensureDataDir()
|
||||
_ = d.ensureDataDir()
|
||||
|
||||
raw, err := json.MarshalIndent(dirs, "", " ")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import (
|
|||
func TestWorkspace_createAndChange(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
newCmd := &WorkspaceNewCommand{}
|
||||
|
|
@ -70,7 +69,6 @@ func TestWorkspace_createAndChange(t *testing.T) {
|
|||
func TestWorkspace_createAndList(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// make sure a vars file doesn't interfere
|
||||
|
|
@ -118,7 +116,6 @@ func TestWorkspace_createAndList(t *testing.T) {
|
|||
func TestWorkspace_createAndShow(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// make sure a vars file doesn't interfere
|
||||
|
|
@ -186,7 +183,6 @@ func TestWorkspace_createAndShow(t *testing.T) {
|
|||
func TestWorkspace_createInvalid(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
envs := []string{"test_a*", "test_b/foo", "../../../test_c", "好_d"}
|
||||
|
|
@ -294,7 +290,6 @@ func TestWorkspace_createWithState(t *testing.T) {
|
|||
|
||||
func TestWorkspace_delete(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// create the workspace directories
|
||||
|
|
@ -347,7 +342,6 @@ func TestWorkspace_delete(t *testing.T) {
|
|||
|
||||
func TestWorkspace_deleteInvalid(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// choose an invalid workspace name
|
||||
|
|
@ -379,7 +373,6 @@ func TestWorkspace_deleteInvalid(t *testing.T) {
|
|||
|
||||
func TestWorkspace_deleteWithState(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
// create the workspace directories
|
||||
|
|
@ -446,7 +439,6 @@ func TestWorkspace_deleteWithState(t *testing.T) {
|
|||
func TestWorkspace_selectWithOrCreate(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := t.TempDir()
|
||||
os.MkdirAll(td, 0755)
|
||||
t.Chdir(td)
|
||||
|
||||
selectCmd := &WorkspaceSelectCommand{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue