Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cmd): add check mode tests for embed #110

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions cmd/gomarkdoc/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
Expand Down
100 changes: 100 additions & 0 deletions testData/embed/README-github-invalid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
This is content before the embed

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# 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>)


<a name="EmbeddedFunc"></a>
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)

```go
func EmbeddedFunc(param int) int
```

EmbeddedFunc is present in embedded content.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->

This is content after the embed

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# 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>)


<a name="EmbeddedFunc"></a>
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)

```go
func EmbeddedFunc(param int) int
```

EmbeddedFunc is present in embedded content.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->

This is content after the second embed

<!-- gomarkdoc:embed:start -->

<!-- Code generated by gomarkdoc. DO NOT EDIT -->

# 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>)


<a name="EmbeddedFunc"></a>
## func [EmbeddedFunc](<https://github.com/princjef/gomarkdoc/blob/master/testData/embed/embed.go#L6>)

```go
func EmbeddedFunc(param int) int
```

EmbeddedFunc is present in embedded content.

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)


<!-- gomarkdoc:embed:end -->

This is content after the third embed