MCPcopy
hub / github.com/opentofu/opentofu / TestStateViews

Function TestStateViews

internal/command/views/state_test.go:27–649  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestStateViews(t *testing.T) {
28 tests := map[string]struct {
29 viewCall func(state State)
30 wantJson []map[string]any
31 wantStdout string
32 wantStderr string
33 ignoreTimestamp bool
34 }{
35 "stateNotFound": {
36 viewCall: func(state State) {
37 state.StateNotFound()
38 },
39 wantJson: []map[string]any{
40 {
41 "@level": "error",
42 "@message": "Error: No state file was found",
43 "@module": "tofu.ui",
44 "diagnostic": map[string]any{
45 "detail": "State management commands require a state file. Run this command in a directory where OpenTofu has been run or use the -state flag to point the command to a specific state location.",
46 "severity": "error",
47 "summary": "No state file was found",
48 },
49 "type": "diagnostic",
50 },
51 },
52 wantStderr: `
53Error: No state file was found
54
55State management commands require a state file. Run this command in a
56directory where OpenTofu has been run or use the -state flag to point the
57command to a specific state location.
58`,
59 },
60 "stateLoadingFailure": {
61 viewCall: func(state State) {
62 state.StateLoadingFailure("failed to read state file")
63 },
64 wantJson: []map[string]any{
65 {
66 "@level": "error",
67 "@message": `Error: Error loading the state`,
68 "@module": "tofu.ui",
69 "diagnostic": map[string]any{
70 "detail": "Please ensure that your OpenTofu state exists and that you've configured it properly. You can use the \"-state\" flag to point OpenTofu at another state file.\n\nCause: failed to read state file",
71 "severity": "error",
72 "summary": "Error loading the state",
73 },
74 "type": "diagnostic",
75 },
76 },
77 wantStderr: `
78Error: Error loading the state
79
80Please ensure that your OpenTofu state exists and that you've configured it
81properly. You can use the "-state" flag to point OpenTofu at another state
82file.
83
84Cause: failed to read state file

Callers

nothing calls this directly

Calls 15

HasErrorsMethod · 0.95
ErrMethod · 0.95
BuildStateFunction · 0.92
NewDefaultProviderFunction · 0.92
NewFunction · 0.92
SourcelessFunction · 0.92
withNewlineFunction · 0.85
testStateHumanFunction · 0.85
testStateJsonFunction · 0.85
testStateMultiFunction · 0.85
StateNotFoundMethod · 0.65

Tested by

no test coverage detected