From 0c5b4bb04e4094d5f9bb004062506e18a46f2cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Thu, 7 Jan 2016 22:07:12 +0100 Subject: [PATCH] Add letsencrypt user test --- letsencrypt/user_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 letsencrypt/user_test.go diff --git a/letsencrypt/user_test.go b/letsencrypt/user_test.go new file mode 100644 index 00000000..e9003e40 --- /dev/null +++ b/letsencrypt/user_test.go @@ -0,0 +1,45 @@ +package letsencrypt + +import ( + "io/ioutil" + "testing" + + "github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/stretchr/testify/assert" + "github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/xenolf/lego/acme" +) + +func tempdir() string { + f, _ := ioutil.TempDir("", "") + return f +} + +func testUser(t *testing.T, email string) { + reg := &acme.RegistrationResource{ + URI: "test.com", + Body: acme.Registration{ + Agreement: "agree?", + }, + } + + user, err := newUser(email) + assert.Nil(t, err) + key := user.GetPrivateKey() + assert.NotNil(t, key) + user.Registration = reg + + err = saveUser(user) + assert.Nil(t, err) + + user, err = getUser(email) + assert.Nil(t, err) + assert.Equal(t, email, user.GetEmail()) + assert.Equal(t, key, user.GetPrivateKey()) + assert.Equal(t, reg, user.GetRegistration()) +} + +func TestUser(t *testing.T) { + directory = Directory(tempdir()) + + testUser(t, "test@test.com") + testUser(t, "") +}