(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func 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: ` |
| 53 | Error: No state file was found |
| 54 | |
| 55 | State management commands require a state file. Run this command in a |
| 56 | directory where OpenTofu has been run or use the -state flag to point the |
| 57 | command 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: ` |
| 78 | Error: Error loading the state |
| 79 | |
| 80 | Please ensure that your OpenTofu state exists and that you've configured it |
| 81 | properly. You can use the "-state" flag to point OpenTofu at another state |
| 82 | file. |
| 83 | |
| 84 | Cause: failed to read state file |
nothing calls this directly
no test coverage detected