github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/test/common_util.go (about) 1 //go:build integration || kind 2 // +build integration kind 3 4 package test 5 6 import ( 7 "encoding/json" 8 "fmt" 9 "io/ioutil" 10 "net/http" 11 "regexp" 12 ) 13 14 func statusRunning(service, branch string, statusOutput []byte) bool { 15 reg, _ := regexp.Compile(service + "\\s+" + branch + "\\s+\\S+\\s+running") 16 return reg.Match(statusOutput) 17 } 18 19 func curl(serv Server, namespace, path string) (string, map[string]interface{}, error) { 20 client := &http.Client{} 21 url := fmt.Sprintf("http://127.0.0.1:%v/%v", serv.APIPort(), path) 22 23 req, _ := http.NewRequest("GET", url, nil) 24 req.Header.Set("Micro-Namespace", namespace) 25 resp, err := client.Do(req) 26 if err != nil { 27 return "", nil, err 28 } 29 defer resp.Body.Close() 30 body, err := ioutil.ReadAll(resp.Body) 31 if err != nil { 32 return "", nil, err 33 } 34 35 m := map[string]interface{}{} 36 return string(body), m, json.Unmarshal(body, &m) 37 }