Skip to content

Commit

Permalink
Add positive test case for editorconfig-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
samtholiya committed Dec 27, 2024
1 parent 342dae4 commit 667e1e5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cmd/editor_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

u "github.com/cloudposse/atmos/pkg/utils"

"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/config"
er "github.com/editorconfig-checker/editorconfig-checker/v3/pkg/error"
"github.com/editorconfig-checker/editorconfig-checker/v3/pkg/files"
Expand Down Expand Up @@ -36,6 +38,7 @@ var editorConfigCmd *cobra.Command = &cobra.Command{

// initializeConfig breaks the initialization cycle by separating the config setup
func initializeConfig() {
u.LogInfo(atmosConfig, fmt.Sprintf("EditorConfig Checker CLI Version: %s", editorConfigVersion))
if configFilePath == "" {
configFilePath = defaultConfigFilePath
}
Expand All @@ -59,8 +62,8 @@ func initializeConfig() {
// runMainLogic contains the main logic
func runMainLogic() {
config := *currentConfig
config.Logger.Debug(config.GetAsString())
config.Logger.Verbose("Exclude Regexp: %s", config.GetExcludesAsRegularExpression())
u.LogDebug(atmosConfig, config.GetAsString())
u.LogTrace(atmosConfig, fmt.Sprintf("Exclude Regexp: %s", config.GetExcludesAsRegularExpression()))

if utils.FileExists(config.Path) && config.Version != "" && config.Version != editorConfigVersion {
config.Logger.Error("Version from config file is not the same as the version of the binary")
Expand Down Expand Up @@ -95,6 +98,7 @@ func runMainLogic() {
}

config.Logger.Verbose("%d files checked", len(filePaths))
u.LogInfo(atmosConfig, "No errors found")
}

// handleReturnableFlags handles early termination flags
Expand Down
38 changes: 38 additions & 0 deletions examples/demo-stacks/.ecrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# EditorConfig for Terraform repository

root = true

# Terraform files
[*.tf]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# HCL files (for Terraform configurations)
[*.hcl]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Atmos configurations (if they exist as YAML or TOML)
[*.yml]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.toml]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
16 changes: 15 additions & 1 deletion tests/test_cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,21 @@ tests:
stderr:
- 'unknown command "non-existent" for "atmos"'
exit_code: 1

- name: atmos validate editorconfig-check
enabled: true
description: "Ensure atmos CLI validates based on the .ecrc file."
workdir: "../examples/demo-stacks/"
command: "atmos"
args:
- "validate"
- "editorconfig-checker"
expect:
stdout:
- "EditorConfig Checker CLI Version: v3.0.0"
- "No errors found"
stderr:
- "^$"
exit_code: 0
- name: atmos describe config -f yaml
enabled: true
description: "Ensure atmos CLI outputs the Atmos configuration in YAML."
Expand Down

0 comments on commit 667e1e5

Please sign in to comment.