I want to test LoadPage and GetData function. While testing LoadPage, I want to mock GetData function, how to do that?
package main
import (
"net/http"
"os"
"fmt"
"io/ioutil"
)
func GetData(url string) (*http.Response,error){
return http.Get(url)
}
func LoadPage(url string) {
resp,err := GetData(url)
if err != nil {
os.Exit(0)
}
data,err :=ioutil.ReadAll(resp.Body)
fmt.Println(string(data))
}
func main() {
var url string
fmt.Scanf("%s", &url)
LoadPage(url)
}
Aucun commentaire:
Enregistrer un commentaire