Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Implement API changes for 4.129.0 #265

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use regexp for URLs
  • Loading branch information
LBGarber committed Jul 11, 2022
commit cfbd32f2c8e4897a1f56ce80c9597a8525f59cc7
6 changes: 3 additions & 3 deletions test/integration/profile_phone_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestPhoneNumber_SendVerificationCode(t *testing.T) {
PhoneNumber: "137-137-1337",
}

httpmock.RegisterResponder("POST", "/v4/profile/phone-number",
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "/profile/phone-number"),
mockRequestBodyValidate(t, requestData, nil))

if err := client.SendPhoneNumberVerificationCode(context.Background(), requestData); err != nil {
Expand All @@ -27,7 +27,7 @@ func TestPhoneNumber_SendVerificationCode(t *testing.T) {
func TestPhoneNumber_Delete(t *testing.T) {
client := createMockClient(t)

httpmock.RegisterResponder("DELETE", "/v4/profile/phone-number",
httpmock.RegisterRegexpResponder("DELETE", mockRequestURL(t, "/profile/phone-number"),
httpmock.NewStringResponder(200, "{}"))

if err := client.DeletePhoneNumber(context.Background()); err != nil {
Expand All @@ -42,7 +42,7 @@ func TestPhoneNumber_Verify(t *testing.T) {
OTPCode: "123456",
}

httpmock.RegisterResponder("POST", "/v4/profile/phone-number/verify",
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "/profile/phone-number/verify"),
mockRequestBodyValidate(t, requestData, nil))

if err := client.VerifyPhoneNumber(context.Background(), requestData); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/profile_security_questions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestSecurityQuestions_List(t *testing.T) {
},
}

httpmock.RegisterResponder("GET", "/v4/profile/security-questions",
httpmock.RegisterRegexpResponder("GET", mockRequestURL(t, "/profile/security-questions"),
httpmock.NewJsonResponderOrPanic(200, &desiredResponse))

questions, err := client.SecurityQuestionsList(context.Background())
Expand All @@ -48,7 +48,7 @@ func TestSecurityQuestions_Answer(t *testing.T) {
},
}

httpmock.RegisterResponder("POST", "/v4/profile/security-questions",
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "/profile/security-questions"),
mockRequestBodyValidate(t, requestData, nil))

if err := client.SecurityQuestionsAnswer(context.Background(), requestData); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/profile_tfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestTwoFactor_CreateSecret(t *testing.T) {
Secret: "verysecureverysecureverysecure",
}

httpmock.RegisterResponder("POST", "/v4/profile/tfa-enable",
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "/profile/tfa-enable"),
httpmock.NewJsonResponderOrPanic(200, expectedResponse))

secret, err := client.CreateTwoFactorSecret(context.Background())
Expand All @@ -33,7 +33,7 @@ func TestTwoFactor_CreateSecret(t *testing.T) {
func TestTwoFactor_Disable(t *testing.T) {
client := createMockClient(t)

httpmock.RegisterResponder("POST", "/v4/profile/tfa-disable",
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "/profile/tfa-disable"),
httpmock.NewStringResponder(200, "{}"))

if err := client.DisableTwoFactor(context.Background()); err != nil {
Expand All @@ -47,7 +47,7 @@ func TestTwoFactor_Confirm(t *testing.T) {
request := linodego.ConfirmTwoFactorOptions{TFACode: "reallycoolandlegittfacode"}
response := linodego.ConfirmTwoFactorResponse{Scratch: "really cool scratch code"}

httpmock.RegisterResponder("POST", "/v4/profile/tfa-enable-confirm",
httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "/profile/tfa-enable-confirm"),
mockRequestBodyValidate(t, request, response))

runResult, err := client.ConfirmTwoFactor(context.Background(), request)
Expand Down
7 changes: 7 additions & 0 deletions test/integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package integration

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -49,3 +52,7 @@ func mockRequestBodyValidate(t *testing.T, expected interface{}, response interf
return httpmock.NewJsonResponse(200, response)
}
}

func mockRequestURL(t *testing.T, path string) *regexp.Regexp {
return regexp.MustCompile(fmt.Sprintf("/[a-zA-Z0-9]+/%s", strings.TrimPrefix(path, "/")))
}