blob: bbf578bfbda103304421fe5b05b7a35b178b4d7d [file] [log] [blame]
package instances
import (
"fmt"
"net/http"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
)
const singleInstanceJson = `
{
"instance": {
"created": "2014-02-13T21:47:13",
"datastore": {
"type": "mysql",
"version": "5.6"
},
"flavor": {
"id": "1",
"links": [
{
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
"rel": "self"
},
{
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
"rel": "bookmark"
}
]
},
"links": [
{
"href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
"rel": "self"
}
],
"hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
"id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
"name": "json_rack_instance",
"status": "BUILD",
"updated": "2014-02-13T21:47:13",
"volume": {
"size": 2
}
}
}
`
func HandleCreateInstanceSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
th.TestJSONRequest(t, r, `
{
"instance": {
"databases": [
{
"character_set": "utf8",
"collate": "utf8_general_ci",
"name": "sampledb"
},
{
"name": "nextround"
}
],
"flavorRef": "1",
"name": "json_rack_instance",
"users": [
{
"databases": [
{
"name": "sampledb"
}
],
"name": "demouser",
"password": "demopassword"
}
],
"volume": {
"size": 2
},
"restorePoint": "1234567890"
}
}
`)
fmt.Fprintf(w, singleInstanceJson)
})
}
func HandleGetInstanceSuccessfully(t *testing.T, id string) {
th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, singleInstanceJson)
})
}
func HandleGetConfigSuccessfully(t *testing.T, id string) {
th.Mux.HandleFunc("/instances/"+id+"/configuration", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `
{
"instance": {
"configuration": {
"basedir": "/usr",
"connect_timeout": "15",
"datadir": "/var/lib/mysql",
"default_storage_engine": "innodb",
"innodb_buffer_pool_instances": "1",
"innodb_buffer_pool_size": "175M",
"innodb_checksum_algorithm": "crc32",
"innodb_data_file_path": "ibdata1:10M:autoextend",
"innodb_file_per_table": "1",
"innodb_io_capacity": "200",
"innodb_log_file_size": "256M",
"innodb_log_files_in_group": "2",
"innodb_open_files": "8192",
"innodb_thread_concurrency": "0",
"join_buffer_size": "1M",
"key_buffer_size": "50M",
"local-infile": "0",
"log-error": "/var/log/mysql/mysqld.log",
"max_allowed_packet": "16M",
"max_connect_errors": "10000",
"max_connections": "40",
"max_heap_table_size": "16M",
"myisam-recover": "BACKUP",
"open_files_limit": "8192",
"performance_schema": "off",
"pid_file": "/var/run/mysqld/mysqld.pid",
"port": "3306",
"query_cache_limit": "1M",
"query_cache_size": "8M",
"query_cache_type": "1",
"read_buffer_size": "256K",
"read_rnd_buffer_size": "1M",
"server_id": "1",
"skip-external-locking": "1",
"skip_name_resolve": "1",
"sort_buffer_size": "256K",
"table_open_cache": "4096",
"thread_stack": "192K",
"tmp_table_size": "16M",
"tmpdir": "/var/tmp",
"user": "mysql",
"wait_timeout": "3600"
}
}
}
`)
})
}
func HandleAssociateGroupSuccessfully(t *testing.T, id string) {
th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestJSONRequest(t, r, `{"instance": {"configuration": "{configGroupID}"}}`)
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, singleInstanceJson)
})
}