File: client_test.go

package info (click to toggle)
golang-github-joyent-gocommon 0.0~git20161202.b787089-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 188 kB
  • sloc: makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// gocommon - Go library to interact with the JoyentCloud
//
//
// Copyright (c) 2013 Joyent Inc.
//
// Written by Daniele Stroppa <daniele.stroppa@joyent.com>
//

package client_test

import (
	"flag"
	"fmt"
	"github.com/joyent/gocommon/client"
	joyenthttp "github.com/joyent/gocommon/http"
//	"github.com/joyent/gocommon/jpc"
	"github.com/joyent/gosign/auth"
	gc "launchpad.net/gocheck"
	"net/http"
//	"testing"
	"time"
)

type ClientSuite struct {
	creds *auth.Credentials
}

var keyName = flag.String("key.name", "", "Specify the full path to the private key, defaults to ~/.ssh/id_rsa")

/* test with keys not feasible
func Test(t *testing.T) {
	creds, err := jpc.CompleteCredentialsFromEnv(*keyName)
	if err != nil {
		t.Fatalf("Error setting up test suite: %v", err)
	}

	gc.Suite(&ClientSuite{creds: creds})
	gc.TestingT(t)
}
*/

func (s *ClientSuite) TestNewClient(c *gc.C) {
	cl := client.NewClient(s.creds.SdcEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)
}

func (s *ClientSuite) TestSendRequest(c *gc.C) {
	cl := client.NewClient(s.creds.SdcEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)

	req := joyenthttp.RequestData{}
	resp := joyenthttp.ResponseData{ExpectedStatus: []int{http.StatusOK}}
	err := cl.SendRequest(client.GET, "", "", &req, &resp)
	c.Assert(err, gc.IsNil)
}

func (s *ClientSuite) TestSignURL(c *gc.C) {
	cl := client.NewClient(s.creds.MantaEndpoint.URL, "", s.creds, nil)
	c.Assert(cl, gc.NotNil)

	path := fmt.Sprintf("/%s/stor", s.creds.UserAuthentication.User)
	singedUrl, err := cl.SignURL(path, time.Now().Add(time.Minute*5))
	c.Assert(err, gc.IsNil)
	c.Assert(singedUrl, gc.Not(gc.Equals), "")
}