This commit is contained in:
neaggarwMS 2020-07-16 13:53:59 -07:00
Родитель 8e073e5f94
Коммит c5095b53c6
1 изменённых файлов: 160 добавлений и 158 удалений

Просмотреть файл

@ -676,202 +676,204 @@ func setEnv(t *testing.T) *httptest.ResponseRecorder {
// IGNORE TEST AS IT IS FAILING. TODO:- Fix it https://msazure.visualstudio.com/One/_workitems/edit/7720083 // IGNORE TEST AS IT IS FAILING. TODO:- Fix it https://msazure.visualstudio.com/One/_workitems/edit/7720083
// // Tests CreateNetwork functionality. // // Tests CreateNetwork functionality.
// func TestCreateNetwork(t *testing.T) {
// fmt.Println("Test: CreateNetwork")
// var body bytes.Buffer /*
// setEnv(t) func TestCreateNetwork(t *testing.T) {
// // info := &cns.CreateNetworkRequest{ fmt.Println("Test: CreateNetwork")
// // NetworkName: "azurenet",
// // }
// // json.NewEncoder(&body).Encode(info) var body bytes.Buffer
setEnv(t)
// info := &cns.CreateNetworkRequest{
// NetworkName: "azurenet",
// }
// // req, err := http.NewRequest(http.MethodPost, cns.CreateNetworkPath, &body) // json.NewEncoder(&body).Encode(info)
// // if err != nil {
// // t.Fatal(err)
// // }
// // w := httptest.NewRecorder() // req, err := http.NewRequest(http.MethodPost, cns.CreateNetworkPath, &body)
// // mux.ServeHTTP(w, req) // if err != nil {
// t.Fatal(err)
// }
// httpc := &http.Client{} // w := httptest.NewRecorder()
// url := defaultCnsURL + cns.CreateNetworkPath // mux.ServeHTTP(w, req)
// log.Printf("CreateNetworkRequest url %v", url)
// payload := &cns.CreateNetworkRequest{ httpc := &http.Client{}
// NetworkName: "azurenet", url := defaultCnsURL + cns.CreateNetworkPath
// } log.Printf("CreateNetworkRequest url %v", url)
// err := json.NewEncoder(&body).Encode(payload) payload := &cns.CreateNetworkRequest{
// if err != nil { NetworkName: "azurenet",
// t.Errorf("encoding json failed with %v", err) }
// }
// res, err := httpc.Post(url, contentTypeJSON, &body) err := json.NewEncoder(&body).Encode(payload)
// if err != nil { if err != nil {
// t.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error()) t.Errorf("encoding json failed with %v", err)
// } }
// defer res.Body.Close() res, err := httpc.Post(url, contentTypeJSON, &body)
// var resp cns.Response if err != nil {
t.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
}
// // err = decodeResponse(res, &resp) defer res.Body.Close()
// // if err != nil || resp.ReturnCode != 0 { var resp cns.Response
// // t.Errorf("CreateNetwork failed with response %+v", resp)
// // } else {
// // fmt.Printf("CreateNetwork Responded with %+v\n", resp)
// // }
// err = json.NewDecoder(res.Body).Decode(&resp) // err = decodeResponse(res, &resp)
// if err != nil { // if err != nil || resp.ReturnCode != 0 {
// t.Errorf("[Azure CNSClient] Error received while parsing ReleaseIPAddress response resp:%v err:%v", res.Body, err.Error()) // t.Errorf("CreateNetwork failed with response %+v", resp)
// } // } else {
// fmt.Printf("CreateNetwork Responded with %+v\n", resp)
// }
// if resp.ReturnCode != 0 { err = json.NewDecoder(res.Body).Decode(&resp)
// t.Errorf("[Azure CNSClient] ReleaseIPAddress received error response :%v", resp.Message) if err != nil {
// // return fmt.Errorf(resp.Message) t.Errorf("[Azure CNSClient] Error received while parsing ReleaseIPAddress response resp:%v err:%v", res.Body, err.Error())
// } }
// }
// // Tests DeleteNetwork functionality. if resp.ReturnCode != 0 {
// func TestDeleteNetwork(t *testing.T) { t.Errorf("[Azure CNSClient] ReleaseIPAddress received error response :%v", resp.Message)
// fmt.Println("Test: DeleteNetwork") // return fmt.Errorf(resp.Message)
}
}
// var body bytes.Buffer func TestDeleteNetwork(t *testing.T) {
// setEnv(t) fmt.Println("Test: DeleteNetwork")
// info := &cns.DeleteNetworkRequest{
// NetworkName: "azurenet",
// }
// json.NewEncoder(&body).Encode(info) var body bytes.Buffer
setEnv(t)
info := &cns.DeleteNetworkRequest{
NetworkName: "azurenet",
}
// req, err := http.NewRequest(http.MethodPost, cns.DeleteNetworkPath, &body) json.NewEncoder(&body).Encode(info)
// if err != nil {
// t.Fatal(err)
// }
// w := httptest.NewRecorder() req, err := http.NewRequest(http.MethodPost, cns.DeleteNetworkPath, &body)
// mux.ServeHTTP(w, req) if err != nil {
// var resp cns.Response t.Fatal(err)
}
// err = decodeResponse(w, &resp) w := httptest.NewRecorder()
// if err != nil || resp.ReturnCode != 0 { mux.ServeHTTP(w, req)
// t.Errorf("DeleteNetwork failed with response %+v", resp) var resp cns.Response
// } else {
// fmt.Printf("DeleteNetwork Responded with %+v\n", resp)
// }
// }
// func TestReserveIPAddress(t *testing.T) { err = decodeResponse(w, &resp)
// fmt.Println("Test: ReserveIPAddress") if err != nil || resp.ReturnCode != 0 {
t.Errorf("DeleteNetwork failed with response %+v", resp)
} else {
fmt.Printf("DeleteNetwork Responded with %+v\n", resp)
}
}
// reserveIPRequest := cns.ReserveIPAddressRequest{ReservationID: "ip01"} func TestReserveIPAddress(t *testing.T) {
// reserveIPRequestJSON := new(bytes.Buffer) fmt.Println("Test: ReserveIPAddress")
// json.NewEncoder(reserveIPRequestJSON).Encode(reserveIPRequest)
// envRequest := cns.SetEnvironmentRequest{Location: "Azure", NetworkType: "Underlay"}
// envRequestJSON := new(bytes.Buffer)
// json.NewEncoder(envRequestJSON).Encode(envRequest)
// req, err := http.NewRequest(http.MethodPost, cns.ReserveIPAddressPath, envRequestJSON) reserveIPRequest := cns.ReserveIPAddressRequest{ReservationID: "ip01"}
// if err != nil { reserveIPRequestJSON := new(bytes.Buffer)
// t.Fatal(err) json.NewEncoder(reserveIPRequestJSON).Encode(reserveIPRequest)
// } envRequest := cns.SetEnvironmentRequest{Location: "Azure", NetworkType: "Underlay"}
envRequestJSON := new(bytes.Buffer)
json.NewEncoder(envRequestJSON).Encode(envRequest)
// w := httptest.NewRecorder() req, err := http.NewRequest(http.MethodPost, cns.ReserveIPAddressPath, envRequestJSON)
// mux.ServeHTTP(w, req) if err != nil {
// var reserveIPAddressResponse cns.ReserveIPAddressResponse t.Fatal(err)
}
// err = decodeResponse(w, &reserveIPAddressResponse) w := httptest.NewRecorder()
// if err != nil || reserveIPAddressResponse.Response.ReturnCode != 0 { mux.ServeHTTP(w, req)
// t.Errorf("SetEnvironment failed with response %+v", reserveIPAddressResponse) var reserveIPAddressResponse cns.ReserveIPAddressResponse
// } else {
// fmt.Printf("SetEnvironment Responded with %+v\n", reserveIPAddressResponse)
// }
// }
// func TestReleaseIPAddress(t *testing.T) { err = decodeResponse(w, &reserveIPAddressResponse)
// fmt.Println("Test: ReleaseIPAddress") if err != nil || reserveIPAddressResponse.Response.ReturnCode != 0 {
t.Errorf("SetEnvironment failed with response %+v", reserveIPAddressResponse)
} else {
fmt.Printf("SetEnvironment Responded with %+v\n", reserveIPAddressResponse)
}
}
// releaseIPRequest := cns.ReleaseIPAddressRequest{ReservationID: "ip01"} func TestReleaseIPAddress(t *testing.T) {
// releaseIPAddressRequestJSON := new(bytes.Buffer) fmt.Println("Test: ReleaseIPAddress")
// json.NewEncoder(releaseIPAddressRequestJSON).Encode(releaseIPRequest)
// req, err := http.NewRequest(http.MethodPost, cns.ReleaseIPAddressPath, releaseIPAddressRequestJSON) releaseIPRequest := cns.ReleaseIPAddressRequest{ReservationID: "ip01"}
// if err != nil { releaseIPAddressRequestJSON := new(bytes.Buffer)
// t.Fatal(err) json.NewEncoder(releaseIPAddressRequestJSON).Encode(releaseIPRequest)
// }
// w := httptest.NewRecorder() req, err := http.NewRequest(http.MethodPost, cns.ReleaseIPAddressPath, releaseIPAddressRequestJSON)
// mux.ServeHTTP(w, req) if err != nil {
// var releaseIPAddressResponse cns.Response t.Fatal(err)
}
// err = decodeResponse(w, &releaseIPAddressResponse) w := httptest.NewRecorder()
// if err != nil || releaseIPAddressResponse.ReturnCode != 0 { mux.ServeHTTP(w, req)
// t.Errorf("SetEnvironment failed with response %+v", releaseIPAddressResponse) var releaseIPAddressResponse cns.Response
// } else {
// fmt.Printf("SetEnvironment Responded with %+v\n", releaseIPAddressResponse)
// }
// }
// func TestGetUnhealthyIPAddresses(t *testing.T) { err = decodeResponse(w, &releaseIPAddressResponse)
// fmt.Println("Test: GetGhostIPAddresses") if err != nil || releaseIPAddressResponse.ReturnCode != 0 {
t.Errorf("SetEnvironment failed with response %+v", releaseIPAddressResponse)
} else {
fmt.Printf("SetEnvironment Responded with %+v\n", releaseIPAddressResponse)
}
}
// req, err := http.NewRequest(http.MethodGet, cns.GetUnhealthyIPAddressesPath, nil) func TestGetUnhealthyIPAddresses(t *testing.T) {
// if err != nil { fmt.Println("Test: GetGhostIPAddresses")
// t.Fatal(err)
// }
// w := httptest.NewRecorder() req, err := http.NewRequest(http.MethodGet, cns.GetUnhealthyIPAddressesPath, nil)
// mux.ServeHTTP(w, req) if err != nil {
// var getIPAddressesResponse cns.GetIPAddressesResponse t.Fatal(err)
}
// err = decodeResponse(w, &getIPAddressesResponse) w := httptest.NewRecorder()
// if err != nil || getIPAddressesResponse.Response.ReturnCode != 0 { mux.ServeHTTP(w, req)
// t.Errorf("GetUnhealthyIPAddresses failed with response %+v", getIPAddressesResponse) var getIPAddressesResponse cns.GetIPAddressesResponse
// } else {
// fmt.Printf("GetUnhealthyIPAddresses Responded with %+v\n", getIPAddressesResponse)
// }
// }
// func TestGetIPAddressUtilization(t *testing.T) { err = decodeResponse(w, &getIPAddressesResponse)
// fmt.Println("Test: GetIPAddressUtilization") if err != nil || getIPAddressesResponse.Response.ReturnCode != 0 {
t.Errorf("GetUnhealthyIPAddresses failed with response %+v", getIPAddressesResponse)
} else {
fmt.Printf("GetUnhealthyIPAddresses Responded with %+v\n", getIPAddressesResponse)
}
}
// req, err := http.NewRequest(http.MethodGet, cns.GetIPAddressUtilizationPath, nil) func TestGetIPAddressUtilization(t *testing.T) {
// if err != nil { fmt.Println("Test: GetIPAddressUtilization")
// t.Fatal(err)
// }
// w := httptest.NewRecorder() req, err := http.NewRequest(http.MethodGet, cns.GetIPAddressUtilizationPath, nil)
// mux.ServeHTTP(w, req) if err != nil {
// var iPAddressesUtilizationResponse cns.IPAddressesUtilizationResponse t.Fatal(err)
}
// err = decodeResponse(w, &iPAddressesUtilizationResponse) w := httptest.NewRecorder()
// if err != nil || iPAddressesUtilizationResponse.Response.ReturnCode != 0 { mux.ServeHTTP(w, req)
// t.Errorf("GetIPAddressUtilization failed with response %+v\n", iPAddressesUtilizationResponse) var iPAddressesUtilizationResponse cns.IPAddressesUtilizationResponse
// } else {
// fmt.Printf("GetIPAddressUtilization Responded with %+v\n", iPAddressesUtilizationResponse)
// }
// }
// func TestGetHostLocalIP(t *testing.T) { err = decodeResponse(w, &iPAddressesUtilizationResponse)
// fmt.Println("Test: GetHostLocalIP") if err != nil || iPAddressesUtilizationResponse.Response.ReturnCode != 0 {
t.Errorf("GetIPAddressUtilization failed with response %+v\n", iPAddressesUtilizationResponse)
} else {
fmt.Printf("GetIPAddressUtilization Responded with %+v\n", iPAddressesUtilizationResponse)
}
}
// setEnv(t) func TestGetHostLocalIP(t *testing.T) {
fmt.Println("Test: GetHostLocalIP")
// req, err := http.NewRequest(http.MethodGet, cns.GetHostLocalIPPath, nil) setEnv(t)
// if err != nil {
// t.Fatal(err)
// }
// w := httptest.NewRecorder() req, err := http.NewRequest(http.MethodGet, cns.GetHostLocalIPPath, nil)
// mux.ServeHTTP(w, req) if err != nil {
// var hostLocalIPAddressResponse cns.HostLocalIPAddressResponse t.Fatal(err)
}
// err = decodeResponse(w, &hostLocalIPAddressResponse) w := httptest.NewRecorder()
// if err != nil || hostLocalIPAddressResponse.Response.ReturnCode != 0 { mux.ServeHTTP(w, req)
// t.Errorf("GetHostLocalIP failed with response %+v", hostLocalIPAddressResponse) var hostLocalIPAddressResponse cns.HostLocalIPAddressResponse
// } else {
// fmt.Printf("GetHostLocalIP Responded with %+v\n", hostLocalIPAddressResponse) err = decodeResponse(w, &hostLocalIPAddressResponse)
// } if err != nil || hostLocalIPAddressResponse.Response.ReturnCode != 0 {
// } t.Errorf("GetHostLocalIP failed with response %+v", hostLocalIPAddressResponse)
} else {
fmt.Printf("GetHostLocalIP Responded with %+v\n", hostLocalIPAddressResponse)
}
}
*/