Ejemplo n.º 1
0
func getService(responseFile string) (*catalogs.Service, *httptest.Server, error) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		slurp, err := ioutil.ReadFile(path.Join("testdata", responseFile))
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		res, err := http.ReadResponse(bufio.NewReader(strings.NewReader(string(slurp))), r)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		defer res.Body.Close()
		bs, err := ioutil.ReadAll(res.Body)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.WriteHeader(res.StatusCode)
		fmt.Fprint(w, string(bs))
	}))

	service, err := catalogs.New(http.DefaultClient)
	if err != nil {
		return service, nil, err
	}
	service.BaseURL = ts.URL
	service.User = os.Getenv("STORE2_USER")
	service.Password = os.Getenv("STORE2_PASSWORD")
	return service, ts, nil
}
Ejemplo n.º 2
0
func GetCatalogsService() (*catalogs.Service, error) {
	client, err := GetHttpClient()
	if err != nil {
		return nil, err
	}
	service, err := catalogs.New(client)
	if err != nil {
		return nil, err
	}
	if url := GetBaseURL(); url != "" {
		service.BaseURL = url
	}
	service.User = getUsername()
	service.Password = getPassword()
	return service, nil
}