Skip to content

Commit

Permalink
🚨 ♻️ Refactoring test
Browse files Browse the repository at this point in the history
  • Loading branch information
lupinthe14th committed Jul 3, 2019
1 parent 056582d commit 4ed7488
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/lupinthe14th/cTLS

go 1.12

require github.com/sirupsen/logrus v1.4.2
require (
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.2.2
)
26 changes: 17 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ package main

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestStatePeerCertificateExpireDate(t *testing.T) {
var tests = []struct {
name string
host string
port string
err bool
}{
{host: "www.google.com", port: "443"},
{host: "smtp.gmail.com", port: "587"},
{name: "No Error", host: "www.google.com", port: "443", err: false},
{name: "No Error", host: "smtp.gmail.com", port: "587", err: false},
{name: "Error", host: "www.google.com", port: "80", err: true},
{name: "Error", host: "smtp.gmail.com", port: "25", err: true},
}

for _, tt := range tests {
expireTime, err := statePeerCertificateExpireDate(tt.host, tt.port)
if err != nil {
t.Error(err)
}
expireJSTTime := expireTime.In(time.FixedZone("Asia/Tokyo", 9*60*60))
t.Logf("Peer Certificates: expire time: %+v", expireJSTTime)
t.Run(tt.name, func(t *testing.T) {
_, err := statePeerCertificateExpireDate(tt.host, tt.port)
if !tt.err {
assert.NoError(t, err)
}
if tt.err {
assert.Error(t, err)
}
})
}
}

0 comments on commit 4ed7488

Please sign in to comment.