1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fixtures.go 11.84 KB
一键复制 编辑 原始数据 按行查看 历史
Thom May 提交于 2015-02-17 10:48 . Basic Rackspace cloud support
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
package lbs
import (
"fmt"
"net/http"
"strconv"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
)
func mockListLBResponse(t *testing.T) {
th.Mux.HandleFunc("/loadbalancers", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"loadBalancers":[
{
"name":"lb-site1",
"id":71,
"protocol":"HTTP",
"port":80,
"algorithm":"RANDOM",
"status":"ACTIVE",
"nodeCount":3,
"virtualIps":[
{
"id":403,
"address":"206.55.130.1",
"type":"PUBLIC",
"ipVersion":"IPV4"
}
],
"created":{
"time":"2010-11-30T03:23:42Z"
},
"updated":{
"time":"2010-11-30T03:23:44Z"
}
},
{
"name":"lb-site2",
"id":72,
"created":{
"time":"2011-11-30T03:23:42Z"
},
"updated":{
"time":"2011-11-30T03:23:44Z"
}
},
{
"name":"lb-site3",
"id":73,
"created":{
"time":"2012-11-30T03:23:42Z"
},
"updated":{
"time":"2012-11-30T03:23:44Z"
}
}
]
}
`)
})
}
func mockCreateLBResponse(t *testing.T) {
th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
th.TestJSONRequest(t, r, `
{
"loadBalancer": {
"name": "a-new-loadbalancer",
"port": 80,
"protocol": "HTTP",
"virtualIps": [
{
"id": 2341
},
{
"id": 900001
}
],
"nodes": [
{
"address": "10.1.1.1",
"port": 80,
"condition": "ENABLED"
}
]
}
}
`)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusAccepted)
fmt.Fprintf(w, `
{
"loadBalancer": {
"name": "a-new-loadbalancer",
"id": 144,
"protocol": "HTTP",
"halfClosed": false,
"port": 83,
"algorithm": "RANDOM",
"status": "BUILD",
"timeout": 30,
"cluster": {
"name": "ztm-n01.staging1.lbaas.rackspace.net"
},
"nodes": [
{
"address": "10.1.1.1",
"id": 653,
"port": 80,
"status": "ONLINE",
"condition": "ENABLED",
"weight": 1
}
],
"virtualIps": [
{
"address": "206.10.10.210",
"id": 39,
"type": "PUBLIC",
"ipVersion": "IPV4"
},
{
"address": "2001:4801:79f1:0002:711b:be4c:0000:0021",
"id": 900001,
"type": "PUBLIC",
"ipVersion": "IPV6"
}
],
"created": {
"time": "2010-11-30T03:23:42Z"
},
"updated": {
"time": "2010-11-30T03:23:44Z"
},
"connectionLogging": {
"enabled": false
}
}
}
`)
})
}
func mockBatchDeleteLBResponse(t *testing.T, ids []int) {
th.Mux.HandleFunc("/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
r.ParseForm()
for k, v := range ids {
fids := r.Form["id"]
th.AssertEquals(t, strconv.Itoa(v), fids[k])
}
w.WriteHeader(http.StatusAccepted)
})
}
func mockDeleteLBResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id), func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}
func mockGetLBResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"loadBalancer": {
"id": 2000,
"name": "sample-loadbalancer",
"protocol": "HTTP",
"port": 80,
"algorithm": "RANDOM",
"status": "ACTIVE",
"timeout": 30,
"connectionLogging": {
"enabled": true
},
"virtualIps": [
{
"id": 1000,
"address": "206.10.10.210",
"type": "PUBLIC",
"ipVersion": "IPV4"
}
],
"nodes": [
{
"id": 1041,
"address": "10.1.1.1",
"port": 80,
"condition": "ENABLED",
"status": "ONLINE"
},
{
"id": 1411,
"address": "10.1.1.2",
"port": 80,
"condition": "ENABLED",
"status": "ONLINE"
}
],
"sessionPersistence": {
"persistenceType": "HTTP_COOKIE"
},
"connectionThrottle": {
"maxConnections": 100
},
"cluster": {
"name": "c1.dfw1"
},
"created": {
"time": "2010-11-30T03:23:42Z"
},
"updated": {
"time": "2010-11-30T03:23:44Z"
},
"sourceAddresses": {
"ipv6Public": "2001:4801:79f1:1::1/64",
"ipv4Servicenet": "10.0.0.0",
"ipv4Public": "10.12.99.28"
}
}
}
`)
})
}
func mockUpdateLBResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(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, `
{
"loadBalancer": {
"name": "a-new-loadbalancer",
"protocol": "TCP",
"halfClosed": true,
"algorithm": "RANDOM",
"port": 8080,
"timeout": 100,
"httpsRedirect": false
}
}
`)
w.WriteHeader(http.StatusAccepted)
})
}
func mockListProtocolsResponse(t *testing.T) {
th.Mux.HandleFunc("/loadbalancers/protocols", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"protocols": [
{
"name": "DNS_TCP",
"port": 53
},
{
"name": "DNS_UDP",
"port": 53
},
{
"name": "FTP",
"port": 21
},
{
"name": "HTTP",
"port": 80
},
{
"name": "HTTPS",
"port": 443
},
{
"name": "IMAPS",
"port": 993
},
{
"name": "IMAPv4",
"port": 143
},
{
"name": "LDAP",
"port": 389
},
{
"name": "LDAPS",
"port": 636
},
{
"name": "MYSQL",
"port": 3306
},
{
"name": "POP3",
"port": 110
},
{
"name": "POP3S",
"port": 995
},
{
"name": "SMTP",
"port": 25
},
{
"name": "TCP",
"port": 0
},
{
"name": "TCP_CLIENT_FIRST",
"port": 0
},
{
"name": "UDP",
"port": 0
},
{
"name": "UDP_STREAM",
"port": 0
},
{
"name": "SFTP",
"port": 22
},
{
"name": "TCP_STREAM",
"port": 0
}
]
}
`)
})
}
func mockListAlgorithmsResponse(t *testing.T) {
th.Mux.HandleFunc("/loadbalancers/algorithms", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"algorithms": [
{
"name": "LEAST_CONNECTIONS"
},
{
"name": "RANDOM"
},
{
"name": "ROUND_ROBIN"
},
{
"name": "WEIGHTED_LEAST_CONNECTIONS"
},
{
"name": "WEIGHTED_ROUND_ROBIN"
}
]
}
`)
})
}
func mockGetLoggingResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/connectionlogging", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"connectionLogging": {
"enabled": true
}
}
`)
})
}
func mockEnableLoggingResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/connectionlogging", 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, `
{
"connectionLogging":{
"enabled":true
}
}
`)
w.WriteHeader(http.StatusAccepted)
})
}
func mockDisableLoggingResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/connectionlogging", 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, `
{
"connectionLogging":{
"enabled":false
}
}
`)
w.WriteHeader(http.StatusAccepted)
})
}
func mockGetErrorPageResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"errorpage": {
"content": "<html>DEFAULT ERROR PAGE</html>"
}
}
`)
})
}
func mockSetErrorPageResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", 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, `
{
"errorpage": {
"content": "<html>New error page</html>"
}
}
`)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"errorpage": {
"content": "<html>New error page</html>"
}
}
`)
})
}
func mockDeleteErrorPageResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/errorpage", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
w.WriteHeader(http.StatusOK)
})
}
func mockGetStatsResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/stats", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"connectTimeOut": 10,
"connectError": 20,
"connectFailure": 30,
"dataTimedOut": 40,
"keepAliveTimedOut": 50,
"maxConn": 60,
"currentConn": 40,
"connectTimeOutSsl": 10,
"connectErrorSsl": 20,
"connectFailureSsl": 30,
"dataTimedOutSsl": 40,
"keepAliveTimedOutSsl": 50,
"maxConnSsl": 60,
"currentConnSsl": 40
}
`)
})
}
func mockGetCachingResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/contentcaching", 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")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
"contentCaching": {
"enabled": true
}
}
`)
})
}
func mockEnableCachingResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/contentcaching", 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, `
{
"contentCaching":{
"enabled":true
}
}
`)
w.WriteHeader(http.StatusAccepted)
})
}
func mockDisableCachingResponse(t *testing.T, id int) {
th.Mux.HandleFunc("/loadbalancers/"+strconv.Itoa(id)+"/contentcaching", 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, `
{
"contentCaching":{
"enabled":false
}
}
`)
w.WriteHeader(http.StatusAccepted)
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.16.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891