-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check: Add unit testing for RegistryIndexFileCheck
Closes #4
- Loading branch information
Showing
6 changed files
with
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package check | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRegistryIndexFileCheck(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
BasePath string | ||
Path string | ||
Options *RegistryIndexFileOptions | ||
ExpectError bool | ||
}{ | ||
{ | ||
Name: "valid", | ||
BasePath: "testdata/valid-registry-files", | ||
Path: "index.md", | ||
}, | ||
{ | ||
Name: "invalid extension", | ||
BasePath: "testdata/invalid-registry-files", | ||
Path: "index_invalid_extension.markdown", | ||
ExpectError: true, | ||
}, | ||
{ | ||
Name: "invalid frontmatter", | ||
BasePath: "testdata/invalid-registry-files", | ||
Path: "index_invalid_frontmatter.md", | ||
ExpectError: true, | ||
}, | ||
{ | ||
Name: "invalid frontmatter with layout", | ||
BasePath: "testdata/invalid-registry-files", | ||
Path: "index_with_layout.md", | ||
ExpectError: true, | ||
}, | ||
{ | ||
Name: "invalid frontmatter with subcategory", | ||
BasePath: "testdata/invalid-registry-files", | ||
Path: "index_with_subcategory.md", | ||
ExpectError: true, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
if testCase.Options == nil { | ||
testCase.Options = &RegistryIndexFileOptions{} | ||
} | ||
|
||
if testCase.Options.FileOptions == nil { | ||
testCase.Options.FileOptions = &FileOptions{ | ||
BasePath: testCase.BasePath, | ||
} | ||
} | ||
|
||
got := NewRegistryIndexFileCheck(testCase.Options).Run(testCase.Path) | ||
|
||
if got == nil && testCase.ExpectError { | ||
t.Errorf("expected error, got no error") | ||
} | ||
|
||
if got != nil && !testCase.ExpectError { | ||
t.Errorf("expected no error, got error: %s", got) | ||
} | ||
}) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
check/testdata/invalid-registry-files/index_invalid_extension.markdown
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,9 @@ | ||
--- | ||
page_title: "Example Provider" | ||
description: |- | ||
Example description. | ||
--- | ||
|
||
# Example Provider | ||
|
||
Example contents. |
9 changes: 9 additions & 0 deletions
9
check/testdata/invalid-registry-files/index_invalid_frontmatter.md
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,9 @@ | ||
--- | ||
page_title: "Example Provider" | ||
description: |- | ||
Missing indentation. | ||
--- | ||
|
||
# Example Provider | ||
|
||
Example contents. |
10 changes: 10 additions & 0 deletions
10
check/testdata/invalid-registry-files/index_with_layout.md
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,10 @@ | ||
--- | ||
layout: "example" | ||
page_title: "Example Provider" | ||
description: |- | ||
Example description. | ||
--- | ||
|
||
# Example Provider | ||
|
||
Example contents. |
10 changes: 10 additions & 0 deletions
10
check/testdata/invalid-registry-files/index_with_subcategory.md
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,10 @@ | ||
--- | ||
subcategory: "example" | ||
page_title: "Example Provider" | ||
description: |- | ||
Example description. | ||
--- | ||
|
||
# Example Provider | ||
|
||
Example contents. |
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,9 @@ | ||
--- | ||
page_title: "Example Provider" | ||
description: |- | ||
Example description. | ||
--- | ||
|
||
# Example Provider | ||
|
||
Example contents. |