-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: not allow state operations without a –force flag
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCheckStateCommand(t *testing.T) { | ||
t.Run("Valid state command with --force flag after state command", func(t *testing.T) { | ||
args := []string{"terraform", "state", "--force", "list"} | ||
err := checkStateCommand(args) | ||
if err != nil { | ||
t.Errorf("Expected no error, got: %v", err) | ||
} | ||
}) | ||
|
||
t.Run("Valid state command with --force flag before state command", func(t *testing.T) { | ||
args := []string{"terraform", "--force", "state", "pull"} | ||
err := checkStateCommand(args) | ||
if err != nil { | ||
t.Errorf("Expected no error, got: %v", err) | ||
} | ||
}) | ||
|
||
t.Run("Invalid state command without --force flag", func(t *testing.T) { | ||
args := []string{"terraform", "state", "list"} | ||
err := checkStateCommand(args) | ||
expectedError := "--force flag is required for the 'state' command" | ||
if err == nil || err.Error() != expectedError { | ||
t.Errorf("Expected error: %s, got: %v", expectedError, err) | ||
} | ||
}) | ||
} |