From a975eb7186d8c1481c3706117ccc3a8410e4f10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Depierrepont=20aka=20Toorop?= Date: Sat, 2 May 2015 20:13:00 +0200 Subject: [PATCH] watch --- dkim_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ errors.go | 12 ++++++++++++ watch | 4 ++++ 3 files changed, 58 insertions(+) create mode 100644 dkim_test.go create mode 100644 errors.go create mode 100755 watch diff --git a/dkim_test.go b/dkim_test.go new file mode 100644 index 0000000..f50d857 --- /dev/null +++ b/dkim_test.go @@ -0,0 +1,42 @@ +package dkim + +import ( + "bytes" + "github.com/stretchr/testify/assert" + "testing" +) + +var email = `Received: (qmail 28277 invoked from network); 1 May 2015 09:43:37 -0000 +Received: (qmail 21323 invoked from network); 1 May 2015 09:48:39 -0000 +MIME-Version: 1.0 +Date: Fri, 1 May 2015 11:48:37 +0200 +Message-ID: +Subject: Test DKIM +From: =?UTF-8?Q?St=C3=A9phane_Depierrepont?= +To: =?UTF-8?Q?St=C3=A9phane_Depierrepont?= +Content-Type: text/plain; charset=UTF-8 + + +Hello world +-- +Toorop` + +func Test_NewSigOptions(t *testing.T) { + options := NewSigOptions() + assert.Equal(t, "rsa-sha256", options.Algo) + assert.Equal(t, "simple/simple", options.Canonicalization) +} + +func Test_Sign(t *testing.T) { + emailReader := bytes.NewReader([]byte(email)) + options := NewSigOptions() + _, err := Sign(emailReader, options) + assert.NotNil(t, err) + // && err No private key + assert.Error(t, ErrConfigNoPrivateKey) + options.PrivateKey = "toto" + _, err = Sign(emailReader, options) + // No + assert.Error(t, ErrConfigNoDomain) + +} diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..5e33429 --- /dev/null +++ b/errors.go @@ -0,0 +1,12 @@ +package dkim + +import ( + "errors" +) + +var ( + // ErrConfigNoPrivateKey when there not private key in config + ErrConfigNoPrivateKey = errors.New("private key not defined in config") + // ErrConfigNoDomain when there is no domain defined in config + ErrConfigNoDomain = errors.New("domain not defined in config") +) diff --git a/watch b/watch new file mode 100755 index 0000000..13bcff7 --- /dev/null +++ b/watch @@ -0,0 +1,4 @@ +while true +do +inotifywait -q -r -e modify,attrib,close_write,move,create,delete . && go test -v +done \ No newline at end of file