diff --git a/Makefile b/Makefile index 987e10c..1498bbb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pipeline.go b/pipeline.go index 537f2a6..b55dc7d 100644 --- a/pipeline.go +++ b/pipeline.go @@ -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 } diff --git a/validate.go b/validate.go index da19887..dc0ca3a 100644 --- a/validate.go +++ b/validate.go @@ -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 { diff --git a/validate_test.go b/validate_test.go index cd57bcc..2ab54fd 100644 --- a/validate_test.go +++ b/validate_test.go @@ -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() + } + }) + } }