mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
formatting
This commit is contained in:
parent
daab24eb2f
commit
3a7b411789
3 changed files with 17 additions and 22 deletions
|
|
@ -16,19 +16,19 @@ import (
|
|||
// NewPatternMatcher compiles a new list of regular expression from
|
||||
// a given list of strings.
|
||||
func TestNewPatternMatcher(t *testing.T) {
|
||||
var regex []string
|
||||
var regex []string
|
||||
if pm, err := NewPatternMatcher(regex); pm == nil || err != nil {
|
||||
t.Errorf("Failure: Did not compile valid regex pattern")
|
||||
t.Errorf("Failure: Did not compile valid regex pattern")
|
||||
}
|
||||
regex = append(regex, "++")
|
||||
if pm, err := NewPatternMatcher(regex); pm != nil || err == nil {
|
||||
t.Errorf("Failure: No error thrown at invalid compile pattern")
|
||||
t.Errorf("Failure: No error thrown at invalid compile pattern")
|
||||
}
|
||||
}
|
||||
|
||||
// Matches returns true if the given string matches any of the expressions.
|
||||
func TestMatches(t *testing.T) {
|
||||
regex := []string{"a"}
|
||||
regex := []string{"a"}
|
||||
pm, _ := NewPatternMatcher(regex)
|
||||
if !pm.Matches("a") {
|
||||
t.Errorf("Failure: Did not match two identical strings")
|
||||
|
|
|
|||
|
|
@ -9,18 +9,17 @@
|
|||
package misc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"bytes"
|
||||
"mime/multipart"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
// CreateFormFile creates an [io.Writer] like [mime/multipart.Writer.CreateFromFile].
|
||||
// This version allows to set the mime type, too.
|
||||
func TestCreateFormFile( t *testing.T) {
|
||||
func TestCreateFormFile(t *testing.T) {
|
||||
body := new(bytes.Buffer)
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
|
||||
_, err := CreateFormFile(writer, "csaf", "data", "application/json")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create an io.Writer via CreateFormFile")
|
||||
|
|
|
|||
|
|
@ -10,12 +10,10 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestNewTimeInterval(t *testing.T) {
|
||||
var before time.Time
|
||||
before = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
|
|
@ -24,7 +22,6 @@ func TestNewTimeInterval(t *testing.T) {
|
|||
NewTimeInterval(after, before)
|
||||
}
|
||||
|
||||
|
||||
func TestGuessDate(t *testing.T) {
|
||||
if _, guess := guessDate("2006-01-02T15:04:05"); !guess {
|
||||
t.Errorf("Failure: Could not guess valid Date from valid string")
|
||||
|
|
@ -34,12 +31,11 @@ func TestGuessDate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func TestUnmarshalText(t *testing.T) {
|
||||
testTimeRange := NewTimeInterval(
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
|
||||
byteSlice := []byte{'3', 'h'}
|
||||
byteSlice := []byte{'3', 'h'}
|
||||
var emptySlice []byte
|
||||
if testTimeRange.UnmarshalText(byteSlice) != nil {
|
||||
t.Errorf(testTimeRange.UnmarshalText(byteSlice).Error())
|
||||
|
|
@ -51,17 +47,17 @@ func TestUnmarshalText(t *testing.T) {
|
|||
|
||||
func TestMarshalJSON(t *testing.T) {
|
||||
testTimeRange := NewTimeInterval(
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
|
||||
testTimeRange.MarshalJSON()
|
||||
}
|
||||
|
||||
func TestUnmarshalFlag(t *testing.T){
|
||||
func TestUnmarshalFlag(t *testing.T) {
|
||||
testTimeRange := NewTimeInterval(
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
|
||||
if err := testTimeRange.UnmarshalFlag("3h"); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
if err := testTimeRange.UnmarshalFlag("2006-01-02T15:04:05"); err != nil {
|
||||
t.Errorf(err.Error())
|
||||
|
|
@ -84,6 +80,6 @@ func TestContains(t *testing.T) {
|
|||
testTimeRange := NewTimeInterval(
|
||||
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
|
||||
testPointInTime := time.Date(2010, time.March, 10, 23, 0, 0, 0, time.UTC)
|
||||
testPointInTime := time.Date(2010, time.March, 10, 23, 0, 0, 0, time.UTC)
|
||||
testTimeRange.Contains(testPointInTime)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue