From 8b1606ae4e72fc0a2a8bfa2d3d280245afc2d006 Mon Sep 17 00:00:00 2001 From: Jeff Principe Date: Sat, 19 Aug 2023 11:16:30 -0700 Subject: [PATCH] test(cmd): add check mode tests for embed (#110) --- cmd/gomarkdoc/command_test.go | 44 +++++++++++ testData/embed/README-github-invalid.md | 100 ++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 testData/embed/README-github-invalid.md diff --git a/cmd/gomarkdoc/command_test.go b/cmd/gomarkdoc/command_test.go index 2d86b0c..f84b16b 100644 --- a/cmd/gomarkdoc/command_test.go +++ b/cmd/gomarkdoc/command_test.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "log" "os" "path/filepath" "strings" @@ -292,6 +293,49 @@ func TestCommand_embed(t *testing.T) { verify(t, "./embed", "github") } +func TestCommand_embed_check(t *testing.T) { + is := is.New(t) + + err := os.Chdir(filepath.Join(wd, "../../testData")) + is.NoErr(err) + + os.Args = []string{ + "gomarkdoc", "./embed", + "--embed", + "--check", + "-o", "{{.Dir}}/README-github-invalid.md", + "--repository.url", "https://github.com/princjef/gomarkdoc", + "--repository.default-branch", "master", + "--repository.path", "/testData/", + } + cleanup(t, "embed") + + log.SetFlags(0) + + cmd := buildCommand() + + err = cmd.Execute() + is.True(err != nil) // Should fail + + os.Args = []string{ + "gomarkdoc", "./embed", + "--embed", + "--check", + "-o", "{{.Dir}}/README-github.md", + "--repository.url", "https://github.com/princjef/gomarkdoc", + "--repository.default-branch", "master", + "--repository.path", "/testData/", + } + cleanup(t, "embed") + + log.SetFlags(0) + + cmd = buildCommand() + + err = cmd.Execute() + is.NoErr(err) // Should pass +} + func TestCompare(t *testing.T) { tests := []struct { b1, b2 []byte diff --git a/testData/embed/README-github-invalid.md b/testData/embed/README-github-invalid.md new file mode 100644 index 0000000..fb40f58 --- /dev/null +++ b/testData/embed/README-github-invalid.md @@ -0,0 +1,100 @@ +This is content before the embed + + + + + +# embed + +```go +import "github.com/princjef/gomarkdoc/testData/embed" +``` + +Package embed tests out embedding of documentation in an existing readme. This is an extra comment that is invalid. + +## Index + +- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>) + + + +## func [EmbeddedFunc]() + +```go +func EmbeddedFunc(param int) int +``` + +EmbeddedFunc is present in embedded content. + +Generated by [gomarkdoc]() + + + + +This is content after the embed + + + + + +# embed + +```go +import "github.com/princjef/gomarkdoc/testData/embed" +``` + +Package embed tests out embedding of documentation in an existing readme. + +## Index + +- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>) + + + +## func [EmbeddedFunc]() + +```go +func EmbeddedFunc(param int) int +``` + +EmbeddedFunc is present in embedded content. + +Generated by [gomarkdoc]() + + + + +This is content after the second embed + + + + + +# embed + +```go +import "github.com/princjef/gomarkdoc/testData/embed" +``` + +Package embed tests out embedding of documentation in an existing readme. + +## Index + +- [func EmbeddedFunc\(param int\) int](<#EmbeddedFunc>) + + + +## func [EmbeddedFunc]() + +```go +func EmbeddedFunc(param int) int +``` + +EmbeddedFunc is present in embedded content. + +Generated by [gomarkdoc]() + + + + +This is content after the third embed \ No newline at end of file