Skip to content

Instantly share code, notes, and snippets.

@napolux
Created April 15, 2019 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save napolux/6f45ebf5540ec640e4f46170af422711 to your computer and use it in GitHub Desktop.
Save napolux/6f45ebf5540ec640e4f46170af422711 to your computer and use it in GitHub Desktop.
service_test.go
package napodate
import (
"context"
"testing"
"time"
)
func TestStatus(t *testing.T) {
srv, ctx := setup()
s, err := srv.Status(ctx)
if err != nil {
t.Errorf("Error: %s", err)
}
// testing status
ok := s == "ok"
if !ok {
t.Errorf("expected service to be ok")
}
}
func TestGet(t *testing.T) {
srv, ctx := setup()
d, err := srv.Get(ctx)
if err != nil {
t.Errorf("Error: %s", err)
}
time := time.Now()
today := time.Format("02/01/2006")
// testing today's date
ok := today == d
if !ok {
t.Errorf("expected dates to be equal")
}
}
func TestValidate(t *testing.T) {
srv, ctx := setup()
b, err := srv.Validate(ctx, "31/12/2019")
if err != nil {
t.Errorf("Error: %s", err)
}
// testing that the date is valid
if !b {
t.Errorf("date should be valid")
}
// testing an invalid date
b, err = srv.Validate(ctx, "31/31/2019")
if b {
t.Errorf("date should be invalid")
}
// testing a USA date date
b, err = srv.Validate(ctx, "12/31/2019")
if b {
t.Errorf("USA date should be invalid")
}
}
func setup() (srv Service, ctx context.Context) {
return NewService(), context.Background()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment