-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement parser command for JSON output (#9)
* feat: Add IsValidFileSystemSource func * feat: Implement parsing command * feat: Add verbose logging to parse command * chore: go mod tidy
- Loading branch information
1 parent
dedcc35
commit 37011bc
Showing
12 changed files
with
186 additions
and
13 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 |
---|---|---|
|
@@ -26,4 +26,10 @@ go.work | |
glass | ||
|
||
# WIP | ||
docs/how_to_guides/* | ||
docs/how_to_guides/* | ||
|
||
# Default parser output | ||
/out | ||
|
||
# Vscode | ||
.vscode |
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
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,46 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/glass-cms/glasscms/cmd" | ||
"github.com/glass-cms/glasscms/item" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ParseCommand(t *testing.T) { | ||
t.Parallel() | ||
|
||
tempDir, err := os.MkdirTemp("", "glasscms") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tempDir) | ||
|
||
command := cmd.NewParseCommand() | ||
command.SetArgs([]string{"../docs/commands", fmt.Sprintf("--%s", cmd.ArgOutput), tempDir}) | ||
|
||
err = command.Command.Execute() | ||
require.NoError(t, err) | ||
|
||
// Assert that the output directory contains the expected JSON file. | ||
// And that the file is not empty. | ||
|
||
// Read the JSON file. | ||
var items []*item.Item | ||
file, err := os.Open(filepath.Join(tempDir, "output.json")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = json.NewDecoder(file).Decode(&items) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
require.NotEmpty(t, items) | ||
} |
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
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
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
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