Skip to content

Commit

Permalink
Merge pull request #49 from marcosinger/tests/licence_date_range
Browse files Browse the repository at this point in the history
tests(License): The end year in the license file should be current year
  • Loading branch information
Matt Bernier committed Nov 16, 2017
2 parents d1ee6ad + b058d8e commit 78ef15f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions smtpapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import (
"encoding/json"
"io/ioutil"
"reflect"
"regexp"
"strconv"
"strings"
"testing"
"time"
)

func exampleJson() map[string]interface{} {
Expand Down Expand Up @@ -372,3 +376,29 @@ func TestMarshalUnmarshall(t *testing.T) {
t.Errorf("Expected %v, but got %v", header, newHeader)
}
}

func TestLicenceDate(t *testing.T) {
b, err := ioutil.ReadFile("./LICENSE.txt")

if err != nil {
t.Fatalf("cannot open license file; got %v", err)
}

r := regexp.MustCompile("(\\d+-\\d+)")
dates := r.FindString(string(b))

if dates == "" {
t.Fatal("cannot find licence date range in the license file")
}

lastDate := strings.Split(dates, "-")[1]
maxLicenseYear, err := strconv.Atoi(lastDate)

if err != nil {
t.Fatalf("cannot convert licence date to int; got %v", err)
}

if maxLicenseYear != time.Now().Year() {
t.Fatalf("end licence year must be %d; got %d", time.Now().Year(), maxLicenseYear)
}
}

0 comments on commit 78ef15f

Please sign in to comment.