<commit_before>// Copyright 2015 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package digitalocean

import (
    "fmt"
    "net/http"
    "net/http/httptest"

    "testing"
    "gopkg.in/check.v1"

    "github.com/tsuru/config"
    "github.com/tsuru/tsuru/iaas"
)

func Test(t *testing.T) { check.TestingT(t) }

func (s *digitaloceanSuite) SetUpSuite(c *check.C) {
    config.Set("iaas:digitalocean:token", "test")
}

type digitaloceanSuite struct{}

var _ = check.Suite(&digitaloceanSuite{})

func (s *digitaloceanSuite) TestCreateMachine(c *check.C) {
    fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, `{"droplet": {"id": 1, "status": "active", "networks": {"v4": [{"ip_address": "172.16.58.3", "netmask": "255.255.240.0", "gateway": "172.16.17.32", "type": "public"}], "v6": [{"ip_address": "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "netmask": 64, "gateway": "fc00:db20:35b:7399::5", "type": "public"}]}}}`)
    }))
    config.Set("iaas:digitalocean:url", fakeServer.URL)
    do := NewDigitalOceanIaas()
    params := map[string]string{"name": "example.com",
                              "region": "nyc3",
                              "size": "512mb",
                              "image": "ubuntu-14-04-x64"}

    m, err := do.CreateMachine(params)
    c.Assert(err, check.IsNil)
    c.Assert(m, check.NotNil)
    c.Assert(m.Address, check.Equals, "172.16.58.3")
    c.Assert(m.Id, check.Equals, "1")
    c.Assert(m.Status, check.Equals, "active")
}

func (s *digitaloceanSuite) TestDeleteMachine(c *check.C) {
    fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
         w.WriteHeader(204)
         w.Header().Set("Content-type", "application/json")
    }))
    config.Set("iaas:digitalocean:url", fakeServer.URL)
    do := NewDigitalOceanIaas()
    machine := iaas.Machine{Id: "myMachineId", CreationParams: map[string]string{"projectid": "projid"}}
    err := do.DeleteMachine(&machine)
    c.Assert(err, check.IsNil)
}
<commit_msg>iaas/digitalocean: go fmt<commit_after>// Copyright 2015 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package digitalocean

import (
	"fmt"
	"net/http"
	"net/http/httptest"

	"gopkg.in/check.v1"
	"testing"

	"github.com/tsuru/config"
	"github.com/tsuru/tsuru/iaas"
)

func Test(t *testing.T) { check.TestingT(t) }

func (s *digitaloceanSuite) SetUpSuite(c *check.C) {
	config.Set("iaas:digitalocean:token", "test")
}

type digitaloceanSuite struct{}

var _ = check.Suite(&digitaloceanSuite{})

func (s *digitaloceanSuite) TestCreateMachine(c *check.C) {
	fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, `{"droplet": {"id": 1, "status": "active", "networks": {"v4": [{"ip_address": "172.16.58.3", "netmask": "255.255.240.0", "gateway": "172.16.17.32", "type": "public"}], "v6": [{"ip_address": "fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b", "netmask": 64, "gateway": "fc00:db20:35b:7399::5", "type": "public"}]}}}`)
	}))
	config.Set("iaas:digitalocean:url", fakeServer.URL)
	do := NewDigitalOceanIaas()
	params := map[string]string{"name": "example.com",
		"region": "nyc3",
		"size":   "512mb",
		"image":  "ubuntu-14-04-x64"}

	m, err := do.CreateMachine(params)
	c.Assert(err, check.IsNil)
	c.Assert(m, check.NotNil)
	c.Assert(m.Address, check.Equals, "172.16.58.3")
	c.Assert(m.Id, check.Equals, "1")
	c.Assert(m.Status, check.Equals, "active")
}

func (s *digitaloceanSuite) TestDeleteMachine(c *check.C) {
	fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(204)
		w.Header().Set("Content-type", "application/json")
	}))
	config.Set("iaas:digitalocean:url", fakeServer.URL)
	do := NewDigitalOceanIaas()
	machine := iaas.Machine{Id: "myMachineId", CreationParams: map[string]string{"projectid": "projid"}}
	err := do.DeleteMachine(&machine)
	c.Assert(err, check.IsNil)
}

{'fraction_non_alphanumeric': 0.18706419812454916, 'fraction_numerical': 0.042798749699446983, 'mean_word_length': 4.259165613147914, 'pattern_counts': {'":': 38, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '99795', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1581, 'n_words': 290}