Skip to content

Commit

Permalink
check: Add unit testing for RegistryIndexFileCheck
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
bflad committed Dec 16, 2019
1 parent 7f7e1b6 commit 01f0b35
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
69 changes: 69 additions & 0 deletions check/registry_index_file_test.go
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)
}
})
}
}
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.
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 check/testdata/invalid-registry-files/index_with_layout.md
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 check/testdata/invalid-registry-files/index_with_subcategory.md
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.
9 changes: 9 additions & 0 deletions check/testdata/valid-registry-files/index.md
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.

0 comments on commit 01f0b35

Please sign in to comment.