Skip to content

Instantly share code, notes, and snippets.

@RyanRLong
Created August 13, 2020 15:56
Show Gist options
  • Select an option

  • Save RyanRLong/04bfa7f8854e33a5cee255071b590b1d to your computer and use it in GitHub Desktop.

Select an option

Save RyanRLong/04bfa7f8854e33a5cee255071b590b1d to your computer and use it in GitHub Desktop.
Go Test Harness
package filters
import (
"testing"
"time"
"github.com/SaltyCatFish/caperrors/pkg/file"
)
type AfterResult struct {
file file.File
time time.Time
expected bool
}
var afterResults = []AfterResult{
{
file: file.NewFile("", NewModTimeMock(time.Date(2021, time.January, 1, 0, 0, 0, 0, time.Local))),
time: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.Local),
expected: true,
},
{
file: file.NewFile("", NewModTimeMock(time.Date(2020, time.January, 1, 0, 0, 0, 0, time.Local))),
time: time.Date(2021, time.January, 1, 0, 0, 0, 0, time.Local),
expected: false,
},
{
file: file.NewFile("", NewModTimeMock(time.Date(2020, time.January, 1, 0, 0, 0, 0, time.Local))),
time: time.Time{},
expected: true,
},
}
func TestAfter(t *testing.T) {
for _, test := range afterResults {
a := NewAfter(test.time)
result := a.OK(test.file)
if result != test.expected {
t.Errorf("%v: Expected %v, got %v", test.file.ModTime(), test.expected, result)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment