Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 12 | const singleInstanceJson = ` |
| 13 | { |
| 14 | "instance": { |
| 15 | "created": "2014-02-13T21:47:13", |
| 16 | "datastore": { |
| 17 | "type": "mysql", |
| 18 | "version": "5.6" |
| 19 | }, |
| 20 | "flavor": { |
| 21 | "id": "1", |
| 22 | "links": [ |
| 23 | { |
| 24 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", |
| 25 | "rel": "self" |
| 26 | }, |
| 27 | { |
| 28 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", |
| 29 | "rel": "bookmark" |
| 30 | } |
| 31 | ] |
| 32 | }, |
| 33 | "links": [ |
| 34 | { |
| 35 | "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1", |
| 36 | "rel": "self" |
| 37 | } |
| 38 | ], |
| 39 | "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com", |
| 40 | "id": "d4603f69-ec7e-4e9b-803f-600b9205576f", |
| 41 | "name": "json_rack_instance", |
| 42 | "status": "BUILD", |
| 43 | "updated": "2014-02-13T21:47:13", |
| 44 | "volume": { |
| 45 | "size": 2 |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | ` |
| 50 | |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 51 | func HandleCreateInstanceSuccessfully(t *testing.T) { |
| 52 | th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) { |
| 53 | th.TestMethod(t, r, "POST") |
| 54 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 55 | |
| 56 | w.Header().Set("Content-Type", "application/json") |
| 57 | w.WriteHeader(http.StatusOK) |
| 58 | |
| 59 | th.TestJSONRequest(t, r, ` |
| 60 | { |
| 61 | "instance": { |
| 62 | "databases": [ |
| 63 | { |
| 64 | "character_set": "utf8", |
| 65 | "collate": "utf8_general_ci", |
| 66 | "name": "sampledb" |
| 67 | }, |
| 68 | { |
| 69 | "name": "nextround" |
| 70 | } |
| 71 | ], |
| 72 | "flavorRef": "1", |
| 73 | "name": "json_rack_instance", |
| 74 | "users": [ |
| 75 | { |
| 76 | "databases": [ |
| 77 | { |
| 78 | "name": "sampledb" |
| 79 | } |
| 80 | ], |
| 81 | "name": "demouser", |
| 82 | "password": "demopassword" |
| 83 | } |
| 84 | ], |
| 85 | "volume": { |
| 86 | "size": 2 |
| 87 | }, |
| 88 | "restorePoint": "1234567890" |
| 89 | } |
| 90 | } |
| 91 | `) |
| 92 | |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 93 | fmt.Fprintf(w, singleInstanceJson) |
| 94 | }) |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 95 | } |
Jamie Hannaford | 39d4ffb | 2015-02-10 13:19:44 +0100 | [diff] [blame] | 96 | |
| 97 | func HandleGetInstanceSuccessfully(t *testing.T, id string) { |
| 98 | th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) { |
| 99 | th.TestMethod(t, r, "GET") |
| 100 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 101 | |
| 102 | w.Header().Add("Content-Type", "application/json") |
| 103 | |
| 104 | fmt.Fprintf(w, singleInstanceJson) |
Jamie Hannaford | 6ee7d4a | 2015-02-09 17:26:49 +0100 | [diff] [blame] | 105 | }) |
| 106 | } |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 107 | |
| 108 | func HandleGetConfigSuccessfully(t *testing.T, id string) { |
| 109 | th.Mux.HandleFunc("/instances/"+id+"/configuration", func(w http.ResponseWriter, r *http.Request) { |
| 110 | th.TestMethod(t, r, "GET") |
| 111 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 112 | |
| 113 | w.Header().Add("Content-Type", "application/json") |
| 114 | |
| 115 | fmt.Fprintf(w, ` |
| 116 | { |
| 117 | "instance": { |
| 118 | "configuration": { |
| 119 | "basedir": "/usr", |
| 120 | "connect_timeout": "15", |
| 121 | "datadir": "/var/lib/mysql", |
| 122 | "default_storage_engine": "innodb", |
| 123 | "innodb_buffer_pool_instances": "1", |
| 124 | "innodb_buffer_pool_size": "175M", |
| 125 | "innodb_checksum_algorithm": "crc32", |
| 126 | "innodb_data_file_path": "ibdata1:10M:autoextend", |
| 127 | "innodb_file_per_table": "1", |
| 128 | "innodb_io_capacity": "200", |
| 129 | "innodb_log_file_size": "256M", |
| 130 | "innodb_log_files_in_group": "2", |
| 131 | "innodb_open_files": "8192", |
| 132 | "innodb_thread_concurrency": "0", |
| 133 | "join_buffer_size": "1M", |
| 134 | "key_buffer_size": "50M", |
| 135 | "local-infile": "0", |
| 136 | "log-error": "/var/log/mysql/mysqld.log", |
| 137 | "max_allowed_packet": "16M", |
| 138 | "max_connect_errors": "10000", |
| 139 | "max_connections": "40", |
| 140 | "max_heap_table_size": "16M", |
| 141 | "myisam-recover": "BACKUP", |
| 142 | "open_files_limit": "8192", |
| 143 | "performance_schema": "off", |
| 144 | "pid_file": "/var/run/mysqld/mysqld.pid", |
| 145 | "port": "3306", |
| 146 | "query_cache_limit": "1M", |
| 147 | "query_cache_size": "8M", |
| 148 | "query_cache_type": "1", |
| 149 | "read_buffer_size": "256K", |
| 150 | "read_rnd_buffer_size": "1M", |
| 151 | "server_id": "1", |
| 152 | "skip-external-locking": "1", |
| 153 | "skip_name_resolve": "1", |
| 154 | "sort_buffer_size": "256K", |
| 155 | "table_open_cache": "4096", |
| 156 | "thread_stack": "192K", |
| 157 | "tmp_table_size": "16M", |
| 158 | "tmpdir": "/var/tmp", |
| 159 | "user": "mysql", |
| 160 | "wait_timeout": "3600" |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | `) |
| 165 | }) |
| 166 | } |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 167 | |
| 168 | func HandleAssociateGroupSuccessfully(t *testing.T, id string) { |
| 169 | th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) { |
| 170 | th.TestMethod(t, r, "PUT") |
| 171 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 172 | th.TestJSONRequest(t, r, `{"instance": {"configuration": "{configGroupID}"}}`) |
| 173 | |
| 174 | w.WriteHeader(http.StatusAccepted) |
| 175 | w.Header().Add("Content-Type", "application/json") |
| 176 | |
| 177 | fmt.Fprintf(w, singleInstanceJson) |
| 178 | }) |
| 179 | } |