Unit tests and linting cleanup

main
Nick Dumas 2 years ago
parent 13e1abd65a
commit 5c48fe6b22

@ -95,7 +95,7 @@ GOBUILD = gox -osarch="!darwin/386" -rebuild -gocmd="$(GOCMD)" -arch="$(ARCHES)"
GOCLEAN = $(GOCMD) clean
GOINSTALL = $(GOCMD) install -a -tags "$(BUILD_TAGS)" -ldflags "$(LDFLAGS)"
GOTEST = $(GOCMD) test -v -tags "$(BUILD_TAGS)"
DISABLED_LINTERS = varnamelen,interfacer,ifshort,exhaustivestruct,maligned,varcheck,scopelint,structcheck,deadcode,nosnakecase,golint
DISABLED_LINTERS = varnamelen,interfacer,ifshort,exhaustivestruct,maligned,varcheck,scopelint,structcheck,deadcode,nosnakecase,golint,depguard
GOLINT = golangci-lint run --enable-all --disable "$(DISABLED_LINTERS)" --timeout=30s --tests
GODEP = $(GOCMD) get -d -t
GOFMT = goreturns -w

@ -184,12 +184,10 @@ func extractAttachments(post string) ([]string, error) {
}
func (p *Pipeline) FindAttachments() error {
return nil
}
func (p *Pipeline) MoveAttachments(post string) error {
return nil
}
@ -198,11 +196,9 @@ func (p *Pipeline) FindPosts() error {
}
func (p *Pipeline) SanitizePost(post string) error {
return nil
}
func (p *Pipeline) CopyPost(post string) error {
return nil
}

@ -7,13 +7,12 @@ import (
"io"
"github.com/santhosh-tekuri/jsonschema/v5"
// allow the jsonschema validator to auto-download http-hosted schemas.
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
"gopkg.in/yaml.v3"
)
var (
ErrUnsupportedOutputFormat = errors.New("unspported output format")
)
var ErrUnsupportedOutputFormat = errors.New("unspported output format")
// Validate accepts a Markdown file as input via the Reader
// and parses the frontmatter present, if any. It then
@ -36,7 +35,7 @@ func Validate(schemaURL string, r io.Reader) error {
return fmt.Errorf("error compiling schema: %w", err)
}
return schema.Validate(frontmatter)
return fmt.Errorf("frontmatter failed validation: %w", schema.Validate(frontmatter))
}
func recurseDetails(detailed jsonschema.Detailed, acc map[string]jsonschema.Detailed) map[string]jsonschema.Detailed {

@ -1,18 +1,50 @@
package obp_test
import (
"bytes"
"testing"
"code.ndumas.com/ndumas/obsidian-pipeline"
)
func Test_BasicValidation(t *testing.T) {
t.Parallel()
t.Run("KeyMissing", func(t *testing.T) {
t.Parallel()
t.Fail()
})
tt := []struct {
name string
b *bytes.Buffer
expected error
}{
{
name: "KeyMissing",
b: bytes.NewBufferString(`
---
boop: "bop"
---
# Markdown Content
`),
expected: nil,
},
{
name: "KeyTypeMismatch",
b: bytes.NewBufferString(`
---
title: 2
---
# Markdown Content
`),
expected: nil,
},
}
t.Run("KeyTypeMismatch", func(t *testing.T) {
t.Parallel()
t.Fail()
})
for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
err := obp.Validate("https://schemas.ndumas.com/obsidian/note.schema.json", tc.b)
if err == nil {
t.Log("Expected Validate() to fail on input")
t.Fail()
}
})
}
}

Loading…
Cancel
Save