Skip to content

Commit 78ef15f

Browse files
author
Matt Bernier
authored
Merge pull request #49 from marcosinger/tests/licence_date_range
tests(License): The end year in the license file should be current year
2 parents d1ee6ad + b058d8e commit 78ef15f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

smtpapi_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import (
44
"encoding/json"
55
"io/ioutil"
66
"reflect"
7+
"regexp"
8+
"strconv"
9+
"strings"
710
"testing"
11+
"time"
812
)
913

1014
func exampleJson() map[string]interface{} {
@@ -372,3 +376,29 @@ func TestMarshalUnmarshall(t *testing.T) {
372376
t.Errorf("Expected %v, but got %v", header, newHeader)
373377
}
374378
}
379+
380+
func TestLicenceDate(t *testing.T) {
381+
b, err := ioutil.ReadFile("./LICENSE.txt")
382+
383+
if err != nil {
384+
t.Fatalf("cannot open license file; got %v", err)
385+
}
386+
387+
r := regexp.MustCompile("(\\d+-\\d+)")
388+
dates := r.FindString(string(b))
389+
390+
if dates == "" {
391+
t.Fatal("cannot find licence date range in the license file")
392+
}
393+
394+
lastDate := strings.Split(dates, "-")[1]
395+
maxLicenseYear, err := strconv.Atoi(lastDate)
396+
397+
if err != nil {
398+
t.Fatalf("cannot convert licence date to int; got %v", err)
399+
}
400+
401+
if maxLicenseYear != time.Now().Year() {
402+
t.Fatalf("end licence year must be %d; got %d", time.Now().Year(), maxLicenseYear)
403+
}
404+
}

0 commit comments

Comments
 (0)