2019-03-11 15:54:35 +00:00
|
|
|
package lightsail // import "github.com/xenolf/lego/providers/dns/lightsail"
|
2018-02-18 15:27:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MockResponse represents a predefined response used by a mock server
|
|
|
|
type MockResponse struct {
|
|
|
|
StatusCode int
|
|
|
|
Body string
|
|
|
|
}
|
|
|
|
|
2018-07-01 00:24:20 +00:00
|
|
|
func newMockServer(t *testing.T, responses map[string]MockResponse) *httptest.Server {
|
2018-02-18 15:27:58 +00:00
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
path := r.URL.Path
|
|
|
|
resp, ok := responses[path]
|
|
|
|
if !ok {
|
|
|
|
msg := fmt.Sprintf("Requested path not found in response map: %s", path)
|
|
|
|
require.FailNow(t, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/xml")
|
|
|
|
w.WriteHeader(resp.StatusCode)
|
2018-09-24 19:07:20 +00:00
|
|
|
_, err := w.Write([]byte(resp.Body))
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
2018-02-18 15:27:58 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
return ts
|
|
|
|
}
|