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 GOCLEAN = $(GOCMD) clean
GOINSTALL = $(GOCMD) install -a -tags "$(BUILD_TAGS)" -ldflags "$(LDFLAGS)" GOINSTALL = $(GOCMD) install -a -tags "$(BUILD_TAGS)" -ldflags "$(LDFLAGS)"
GOTEST = $(GOCMD) test -v -tags "$(BUILD_TAGS)" 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 GOLINT = golangci-lint run --enable-all --disable "$(DISABLED_LINTERS)" --timeout=30s --tests
GODEP = $(GOCMD) get -d -t GODEP = $(GOCMD) get -d -t
GOFMT = goreturns -w GOFMT = goreturns -w

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

@ -7,13 +7,12 @@ import (
"io" "io"
"github.com/santhosh-tekuri/jsonschema/v5" "github.com/santhosh-tekuri/jsonschema/v5"
// allow the jsonschema validator to auto-download http-hosted schemas.
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader" _ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
var ( var ErrUnsupportedOutputFormat = errors.New("unspported output format")
ErrUnsupportedOutputFormat = errors.New("unspported output format")
)
// Validate accepts a Markdown file as input via the Reader // Validate accepts a Markdown file as input via the Reader
// and parses the frontmatter present, if any. It then // 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 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 { func recurseDetails(detailed jsonschema.Detailed, acc map[string]jsonschema.Detailed) map[string]jsonschema.Detailed {

@ -1,18 +1,50 @@
package obp_test package obp_test
import ( import (
"bytes"
"testing" "testing"
"code.ndumas.com/ndumas/obsidian-pipeline"
) )
func Test_BasicValidation(t *testing.T) { func Test_BasicValidation(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("KeyMissing", func(t *testing.T) { tt := []struct {
t.Parallel() name string
t.Fail() 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) { for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel() 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() t.Fail()
}
}) })
}
} }

Loading…
Cancel
Save