Skip to content

Commit

Permalink
fix: fixed test;
Browse files Browse the repository at this point in the history
  • Loading branch information
subomi committed Oct 10, 2023
1 parent 7b3883d commit 104f9cd
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions requestmigrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"

Expand Down Expand Up @@ -136,33 +137,27 @@ type oldUser struct {
}
type combineNamesMigration struct{}

func (c *combineNamesMigration) ShouldMigrateRequest(r *http.Request) bool {
return false
}

func (c *combineNamesMigration) MigrateRequest(r *http.Request) error {
return nil
}
func (c *combineNamesMigration) ShouldMigrateConstraint(
url *url.URL,
method string,
body []byte,
isReq bool) bool {

func (c *combineNamesMigration) ShouldMigrateResponse(
req *http.Request,
res *http.Response) bool {
isUserPath := req.URL.Path == "/users"
isGetMethod := req.Method == http.MethodGet
isUserPath := url.Path == "/users"
isGetMethod := method == http.MethodGet
isValidType := isReq == false

return isUserPath && isGetMethod
return isUserPath && isGetMethod && isValidType
}

func (c *combineNamesMigration) MigrateResponse(r *http.Response) error {
body, err := io.ReadAll(r.Body)
if err != nil {
return err
}
func (c *combineNamesMigration) Migrate(
body []byte,
h http.Header) ([]byte, http.Header, error) {

var newuser user
err = json.Unmarshal(body, &newuser)
err := json.Unmarshal(body, &newuser)
if err != nil {
return err
return nil, nil, err
}

var user oldUser
Expand All @@ -171,9 +166,8 @@ func (c *combineNamesMigration) MigrateResponse(r *http.Response) error {

body, err = json.Marshal(&user)
if err != nil {
return err
return nil, nil, err
}

r.Body = io.NopCloser(bytes.NewReader(body))
return nil
return body, h, nil
}

0 comments on commit 104f9cd

Please sign in to comment.