67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package schema
|
|
|
|
import (
|
|
"encoding/json"
|
|
_ "fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
_ "gopkg.in/yaml.v3"
|
|
_ "io"
|
|
_ "log"
|
|
_ "net/http"
|
|
_ "net/http/httptest"
|
|
_ "net/url"
|
|
_ "path/filepath"
|
|
_ "strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type TestData struct {
|
|
Name string `json:"name"`
|
|
Len int `json:"len"`
|
|
Date time.Time `json:"date"`
|
|
}
|
|
|
|
func TestNewSchema(t *testing.T) {
|
|
s := New("testdata", schemaFiles)
|
|
assert.NotNil(t, s)
|
|
}
|
|
|
|
func TestSchemaValidateJSON(t *testing.T) {
|
|
s := New("testdata", schemaFiles)
|
|
assert.NotNil(t, s)
|
|
|
|
// file, _ := filepath.Abs(filepath.Join(TempDir, "fooread.txt"))
|
|
|
|
expectedAtime, atimeErr := time.Parse(time.RFC3339Nano, "2001-12-15T01:01:01.000000001Z")
|
|
assert.Nil(t, atimeErr)
|
|
// expectedTime := expectedAtime.Local().Format(time.RFC3339Nano)
|
|
|
|
/*
|
|
declarationAttributes := `
|
|
name: "%s"
|
|
date: %s
|
|
len: 15
|
|
`
|
|
|
|
decl := fmt.Sprintf(declarationAttributes, file, expectedTime)
|
|
*/
|
|
|
|
testData := &TestData{ Name: "foo", Len: 20, Date: expectedAtime }
|
|
|
|
jsonDoc, jsonErr := json.Marshal(testData)
|
|
assert.Nil(t, jsonErr)
|
|
|
|
schemaErr := s.Validate(string(jsonDoc))
|
|
assert.Nil(t, schemaErr)
|
|
}
|
|
|
|
func TestSchemaValidateSchema(t *testing.T) {
|
|
s := New("testdata", schemaFiles)
|
|
assert.NotNil(t, s)
|
|
|
|
assert.Nil(t, s.ValidateSchema())
|
|
}
|