-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from loispostula/add-tests
✅ Bootstrap tests
- Loading branch information
Showing
8 changed files
with
188 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Tests | ||
on: | ||
- pull_request | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install terraform-docs | ||
uses: jaxxstorm/[email protected] | ||
with: | ||
repo: terraform-docs/terraform-docs | ||
tag: v0.19.0 | ||
- uses: purcell/setup-emacs@master | ||
with: | ||
version: 27.1 | ||
- uses: actions/setup-python@v2 | ||
- uses: conao3/setup-cask@master | ||
- name: Run tests | ||
run: | | ||
cask install | ||
cask exec buttercup -L . test/ |
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,49 @@ | ||
### Emacs ### | ||
# -*- mode: gitignore; -*- | ||
*~ | ||
\#*\# | ||
/.emacs.desktop | ||
/.emacs.desktop.lock | ||
*.elc | ||
auto-save-list | ||
tramp | ||
.\#* | ||
|
||
# Org-mode | ||
.org-id-locations | ||
*_archive | ||
|
||
# flymake-mode | ||
*_flymake.* | ||
|
||
# eshell files | ||
/eshell/history | ||
/eshell/lastdir | ||
|
||
# elpa packages | ||
/elpa/ | ||
|
||
# reftex files | ||
*.rel | ||
|
||
# AUCTeX auto folder | ||
/auto/ | ||
|
||
# cask packages | ||
.cask/ | ||
dist/ | ||
|
||
# Flycheck | ||
flycheck_*.el | ||
|
||
# server auth directory | ||
/server/ | ||
|
||
# projectiles files | ||
.projectile | ||
|
||
# directory configuration | ||
.dir-locals.el | ||
|
||
# network security | ||
/network-security.data |
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,7 @@ | ||
(source gnu) | ||
(source melpa) | ||
|
||
(package-file "terraform-docs.el") | ||
|
||
(development | ||
(depends-on "buttercup")) |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
;; Author: Loïs Postula <[email protected]> | ||
;; URL: https://github.com/loispostula/terraform-docs.el | ||
;; Version: 0.1 | ||
;; Package-Requires: ((emacs "25.1")) | ||
;; Package-Requires: ((emacs "27.1")) | ||
;; Keywords: terraform, tools, docs | ||
|
||
;; This program is free software; you can redistribute it and/or modify | ||
|
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,4 @@ | ||
formatter: "markdown table" | ||
|
||
settings: | ||
hide-empty: true |
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,13 @@ | ||
/** | ||
* terraform-docs.el: | ||
* | ||
* Example of 'test' module. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
required_providers { | ||
random = ">= 2.2.0" | ||
} | ||
} | ||
resource "null_resource" "foo" {} |
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,89 @@ | ||
;;; terraform-docs-spec.el --- Buttercup tests for terraform-docs.el -*- lexical-binding: t; -*- | ||
|
||
(require 'buttercup) | ||
(require 'terraform-docs) | ||
|
||
(defvar terraform-docs-fixtures-dir | ||
(expand-file-name "fixtures" (file-name-directory (or load-file-name buffer-file-name))) | ||
"Directory containing test fixtures for terraform-docs.") | ||
|
||
(defvar terraform-docs-expected-output | ||
"terraform-docs.el: | ||
Example of 'test' module. | ||
## Requirements | ||
| Name | Version | | ||
|------|---------| | ||
| <a name=\"requirement_terraform\"></a> [terraform](#requirement_terraform) | >= 0.12 | | ||
| <a name=\"requirement_random\"></a> [random](#requirement_random) | >= 2.2.0 | | ||
## Providers | ||
| Name | Version | | ||
|------|---------| | ||
| <a name=\"provider_null\"></a> [null](#provider_null) | n/a | | ||
## Resources | ||
| Name | Type | | ||
|------|------| | ||
| [null_resource.foo](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |" | ||
"Expected output generated by terraform-docs for the test fixtures.") | ||
(defun terraform-docs-normalize-output (output) | ||
"Normalize OUTPUT by unescaping escaped characters and trimming whitespace." | ||
(let ((clean-output (replace-regexp-in-string "\\\\" "" output))) ;; Unescape characters | ||
(string-trim clean-output))) ;; Remove leading and trailing whitespace | ||
|
||
(describe "terraform-docs executable" | ||
(it "is available in the system PATH" | ||
(let ((executable (executable-find "terraform-docs"))) | ||
(expect executable :not :to-be nil) | ||
(expect (file-executable-p executable) :to-be t)))) | ||
|
||
(describe "terraform-docs-config-file" | ||
(it "finds the default .terraform-docs.yml file in fixtures" | ||
(let ((config-file (terraform-docs-config-file terraform-docs-fixtures-dir))) | ||
(expect config-file :to-equal | ||
(expand-file-name ".terraform-docs.yml" terraform-docs-fixtures-dir)))) | ||
|
||
(it "returns nil if no configuration file is found" | ||
(let ((terraform-docs-config-name "nonexistent-config.yml")) | ||
(let ((config-file (terraform-docs-config-file terraform-docs-fixtures-dir))) | ||
(expect config-file :to-be nil)))) | ||
|
||
(it "finds a custom configuration file in fixtures" | ||
(let ((terraform-docs-config-name ".custom-docs-config.yml")) | ||
(copy-file (expand-file-name ".terraform-docs.yml" terraform-docs-fixtures-dir) | ||
(expand-file-name ".custom-docs-config.yml" terraform-docs-fixtures-dir) t) | ||
(unwind-protect | ||
(let ((config-file (terraform-docs-config-file terraform-docs-fixtures-dir))) | ||
(expect config-file :to-equal | ||
(expand-file-name ".custom-docs-config.yml" terraform-docs-fixtures-dir))) | ||
(delete-file (expand-file-name ".custom-docs-config.yml" terraform-docs-fixtures-dir)))))) | ||
|
||
(describe "terraform-docs-run" | ||
(it "generates the expected output as a string" | ||
(let* ((output (terraform-docs-run (expand-file-name "main.tf" terraform-docs-fixtures-dir) t)) | ||
(clean-output (terraform-docs-normalize-output (substring-no-properties output)))) | ||
(expect clean-output :to-equal terraform-docs-expected-output)))) | ||
|
||
(describe "terraform-docs-to-file" | ||
(it "creates an output file with the expected content" | ||
(let ((output-file (terraform-docs-to-file (expand-file-name "main.tf" terraform-docs-fixtures-dir)))) | ||
(expect (file-exists-p output-file) :to-be t) | ||
(expect (with-temp-buffer | ||
(insert-file-contents output-file) | ||
(terraform-docs-normalize-output (buffer-string))) | ||
:to-equal terraform-docs-expected-output) | ||
(delete-file output-file)))) | ||
|
||
(describe "terraform-docs-to-file-and-open" | ||
(it "creates an output file and opens it" | ||
(spy-on 'find-file :and-call-fake | ||
(lambda (file) | ||
(expect (file-name-nondirectory file) :to-match "^output-for-fixtures\\.md$"))) | ||
(let ((output-file (terraform-docs-to-file (expand-file-name "main.tf" terraform-docs-fixtures-dir)))) | ||
(terraform-docs-to-file-and-open (expand-file-name "main.tf" terraform-docs-fixtures-dir)) | ||
(delete-file output-file)))) |