Skip to content

Commit

Permalink
Merge 9f60889 into 6f2aed7
Browse files Browse the repository at this point in the history
  • Loading branch information
ozerovandrei committed Apr 19, 2018
2 parents 6f2aed7 + 9f60889 commit ef36a02
Show file tree
Hide file tree
Showing 2 changed files with 361 additions and 0 deletions.
15 changes: 15 additions & 0 deletions selvpcclient/resell/v2/quotas/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,18 @@ var TestUpdateProjectQuotasResponse = []*quotas.Quota{
},
},
}

// TestQuotasInvalidResponseRaw represents a raw invalid quotas response.
const TestQuotasInvalidResponseRaw = `
{
"quotas": {
111: [
{
"region": "ru-2",
"value": 64000,
"zone": "ru-2a"
}
]
}
}
`
346 changes: 346 additions & 0 deletions selvpcclient/resell/v2/quotas/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,75 @@ func TestGetAllQuotasSingle(t *testing.T) {
}
}

func TestGetAllQuotasHTTPError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas",
TestGetAllQuotasResponseRaw, http.MethodGet, http.StatusBadGateway,
&endpointCalled, t)

ctx := context.Background()
allQuotas, httpResponse, err := quotas.GetAll(ctx, testEnv.Client)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetAll method")
}
if err == nil {
t.Fatal("expected error from the GetAll method")
}
if httpResponse.StatusCode != http.StatusBadGateway {
t.Fatalf("expected %d status in the HTTP response, but got %d",
http.StatusBadGateway, httpResponse.StatusCode)
}
}

func TestGetAllQuotasTimeoutError(t *testing.T) {
testEnv := testutils.SetupTestEnv()
testEnv.Server.Close()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()

ctx := context.Background()
allQuotas, _, err := quotas.GetAll(ctx, testEnv.Client)

if allQuotas != nil {
t.Fatal("expected no quotas from the GetAll method")
}
if err == nil {
t.Fatal("expected error from the GetAll method")
}
}

func TestGetAllQuotasUnmarshalError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas",
TestQuotasInvalidResponseRaw, http.MethodGet, http.StatusOK,
&endpointCalled, t)

ctx := context.Background()
allQuotas, _, err := quotas.GetAll(ctx, testEnv.Client)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetAll method")
}
if err == nil {
t.Fatal("expected error from the GetAll method")
}
}

func TestGetFreeQuotas(t *testing.T) {
endpointCalled := false

Expand Down Expand Up @@ -130,6 +199,75 @@ func TestGetFreeQuotasSingle(t *testing.T) {
}
}

func TestGetFreeQuotasHTTPError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas/free",
TestGetFreeQuotasResponseRaw, http.MethodGet, http.StatusBadGateway,
&endpointCalled, t)

ctx := context.Background()
allQuotas, httpResponse, err := quotas.GetFree(ctx, testEnv.Client)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetFree method")
}
if err == nil {
t.Fatal("expected error from the GetFree method")
}
if httpResponse.StatusCode != http.StatusBadGateway {
t.Fatalf("expected %d status in the HTTP response, but got %d",
http.StatusBadGateway, httpResponse.StatusCode)
}
}

func TestGetFreeQuotasTimeoutError(t *testing.T) {
testEnv := testutils.SetupTestEnv()
testEnv.Server.Close()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()

ctx := context.Background()
allQuotas, _, err := quotas.GetFree(ctx, testEnv.Client)

if allQuotas != nil {
t.Fatal("expected no quotas from the GetFree method")
}
if err == nil {
t.Fatal("expected error from the GetFree method")
}
}

func TestGetFreeQuotasUnmarshalError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas/free",
TestQuotasInvalidResponseRaw, http.MethodGet, http.StatusOK,
&endpointCalled, t)

ctx := context.Background()
allQuotas, _, err := quotas.GetFree(ctx, testEnv.Client)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetFree method")
}
if err == nil {
t.Fatal("expected error from the GetFree method")
}
}

func TestGetProjectsQuotas(t *testing.T) {
endpointCalled := false

Expand Down Expand Up @@ -190,6 +328,75 @@ func TestGetProjectsQuotasSingle(t *testing.T) {
}
}

func TestGetProjectsQuotasHTTPError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas/projects",
TestGetProjectsQuotasResponseRaw, http.MethodGet, http.StatusBadGateway,
&endpointCalled, t)

ctx := context.Background()
allQuotas, httpResponse, err := quotas.GetProjectsQuotas(ctx, testEnv.Client)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetProjectsQuotas method")
}
if err == nil {
t.Fatal("expected error from the GetProjectsQuotas method")
}
if httpResponse.StatusCode != http.StatusBadGateway {
t.Fatalf("expected %d status in the HTTP response, but got %d",
http.StatusBadGateway, httpResponse.StatusCode)
}
}

func TestGetProjectsQuotasTimeoutError(t *testing.T) {
testEnv := testutils.SetupTestEnv()
testEnv.Server.Close()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()

ctx := context.Background()
allQuotas, _, err := quotas.GetProjectsQuotas(ctx, testEnv.Client)

if allQuotas != nil {
t.Fatal("expected no quotas from the GetProjectsQuotas method")
}
if err == nil {
t.Fatal("expected error from the GetProjectsQuotas method")
}
}

func TestGetProjectsQuotasUnmarshalError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas/projects",
TestQuotasInvalidResponseRaw, http.MethodGet, http.StatusOK,
&endpointCalled, t)

ctx := context.Background()
allQuotas, _, err := quotas.GetProjectsQuotas(ctx, testEnv.Client)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetProjectsQuotas method")
}
if err == nil {
t.Fatal("expected error from the GetProjectsQuotas method")
}
}

func TestGetProjectQuotas(t *testing.T) {
endpointCalled := false

Expand Down Expand Up @@ -250,6 +457,75 @@ func TestGetProjectQuotasSingle(t *testing.T) {
}
}

func TestGetProjectQuotasHTTPError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas/projects/c83243b3c18a4d109a5f0fe45336af85",
TestGetProjectQuotasResponseRaw, http.MethodGet, http.StatusBadGateway,
&endpointCalled, t)

ctx := context.Background()
allQuotas, httpResponse, err := quotas.GetProjectQuotas(ctx, testEnv.Client, "c83243b3c18a4d109a5f0fe45336af85")

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetProjectQuotas method")
}
if err == nil {
t.Fatal("expected error from the GetProjectQuotas method")
}
if httpResponse.StatusCode != http.StatusBadGateway {
t.Fatalf("expected %d status in the HTTP response, but got %d",
http.StatusBadGateway, httpResponse.StatusCode)
}
}

func TestGetProjectQuotasTimeoutError(t *testing.T) {
testEnv := testutils.SetupTestEnv()
testEnv.Server.Close()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()

ctx := context.Background()
allQuotas, _, err := quotas.GetProjectQuotas(ctx, testEnv.Client, "c83243b3c18a4d109a5f0fe45336af85")

if allQuotas != nil {
t.Fatal("expected no quotas from the GetProjectQuotas method")
}
if err == nil {
t.Fatal("expected error from the GetProjectQuotas method")
}
}

func TestGetProjectQuotasUnmarshalError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithoutBody(testEnv.Mux, "/resell/v2/quotas/projects/c83243b3c18a4d109a5f0fe45336af85",
TestQuotasInvalidResponseRaw, http.MethodGet, http.StatusOK,
&endpointCalled, t)

ctx := context.Background()
allQuotas, _, err := quotas.GetProjectQuotas(ctx, testEnv.Client, "c83243b3c18a4d109a5f0fe45336af85")

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the GetProjectQuotas method")
}
if err == nil {
t.Fatal("expected error from the GetProjectQuotas method")
}
}

func TestUpdateProjectQuotas(t *testing.T) {
endpointCalled := false

Expand All @@ -276,3 +552,73 @@ func TestUpdateProjectQuotas(t *testing.T) {
t.Fatalf("expected %#v, but got %#v", actualResponse, expectedResponse)
}
}

func TestUpdateProjectQuotasHTTPError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithBody(testEnv.Mux, "/resell/v2/quotas/projects/c83243b3c18a4d109a5f0fe45336af85",
"", TestUpdateQuotasOptsRaw, http.MethodPatch, http.StatusBadRequest, &endpointCalled, t)

ctx := context.Background()
updateOpts := TestUpdateQuotasOpts
allQuotas, httpResponse, err := quotas.UpdateProjectQuotas(ctx, testEnv.Client, "c83243b3c18a4d109a5f0fe45336af85", updateOpts)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the Update method")
}
if err == nil {
t.Fatal("expected error from the Update method")
}
if httpResponse.StatusCode != http.StatusBadRequest {
t.Fatalf("expected %d status in the HTTP response, but got %d", http.StatusBadRequest, httpResponse.StatusCode)
}
}

func TestUpdateProjectQuotasTimeoutError(t *testing.T) {
testEnv := testutils.SetupTestEnv()
testEnv.Server.Close()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()

ctx := context.Background()
updateOpts := TestUpdateQuotasOpts
allQuotas, _, err := quotas.UpdateProjectQuotas(ctx, testEnv.Client, "c83243b3c18a4d109a5f0fe45336af85", updateOpts)

if allQuotas != nil {
t.Fatal("expected no quotas from the Update method")
}
if err == nil {
t.Fatal("expected error from the Update method")
}
}

func TestUpdateProjectQuotasUnmarshalError(t *testing.T) {
endpointCalled := false

testEnv := testutils.SetupTestEnv()
defer testEnv.TearDownTestEnv()
testEnv.NewTestResellV2Client()
testutils.HandleReqWithBody(testEnv.Mux, "/resell/v2/quotas/projects/c83243b3c18a4d109a5f0fe45336af85",
TestQuotasInvalidResponseRaw, TestUpdateQuotasOptsRaw, http.MethodPatch,
http.StatusOK, &endpointCalled, t)

ctx := context.Background()
updateOpts := TestUpdateQuotasOpts
allQuotas, _, err := quotas.UpdateProjectQuotas(ctx, testEnv.Client, "c83243b3c18a4d109a5f0fe45336af85", updateOpts)

if !endpointCalled {
t.Fatal("endpoint wasn't called")
}
if allQuotas != nil {
t.Fatal("expected no quotas from the Update method")
}
if err == nil {
t.Fatal("expected error from the Update method")
}
}

0 comments on commit ef36a02

Please sign in to comment.