~allenap/gwacl/destroy-hosted-service

« back to all changes in this revision

Viewing changes to management_test.go

  • Committer: Gavin Panella
  • Date: 2013-07-04 16:29:14 UTC
  • Revision ID: gavin@gromper.net-20130704162914-zyhmukhjxeh7t0sc
Test various failure modes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
474
474
    // The last request deletes the hosted service.
475
475
    assertDeleteHostedServiceRequest(c, api, request.ServiceName, record[5])
476
476
}
 
477
 
 
478
func (suite *suiteDestroyHostedService) TestOkayWhenHostedServiceNotFound(c *C) {
 
479
    var responses []DispatcherResponse
 
480
    // Prepare.
 
481
    responses = []DispatcherResponse{exampleNotFoundResponse}
 
482
    record := []*X509Request{}
 
483
    rigRecordingPreparedResponseDispatcher(&record, responses)
 
484
    // Exercise DestroyHostedService.
 
485
    api := makeAPI(c)
 
486
    request := &DestroyHostedServiceRequest{ServiceName: "service-name"}
 
487
    err := api.DestroyHostedService(request)
 
488
    c.Assert(err, IsNil)
 
489
    c.Check(record, HasLen, 1)
 
490
}
 
491
 
 
492
func (suite *suiteDestroyHostedService) TestOkayWhenDeploymentsNotFound(c *C) {
 
493
    var responses []DispatcherResponse
 
494
    // Prepare.
 
495
    responses = append(responses, makeOKXMLResponse(c, exampleHostedService)...)
 
496
    // Someone else has destroyed the deployments in the meantime.
 
497
    responses = append(responses, exampleNotFoundResponse, exampleNotFoundResponse)
 
498
    // Success deleting the hosted service.
 
499
    responses = append(responses, exampleOkayResponse)
 
500
    record := []*X509Request{}
 
501
    rigRecordingPreparedResponseDispatcher(&record, responses)
 
502
    // Exercise DestroyHostedService.
 
503
    api := makeAPI(c)
 
504
    request := &DestroyHostedServiceRequest{ServiceName: "service-name"}
 
505
    err := api.DestroyHostedService(request)
 
506
    c.Assert(err, IsNil)
 
507
    c.Check(record, HasLen, 4)
 
508
    assertGetDeploymentRequest(c, api, &GetDeploymentRequest{
 
509
        request.ServiceName, "one"}, record[1])
 
510
    assertGetDeploymentRequest(c, api, &GetDeploymentRequest{
 
511
        request.ServiceName, "two"}, record[2])
 
512
    assertDeleteHostedServiceRequest(c, api, request.ServiceName, record[3])
 
513
}
 
514
 
 
515
func (suite *suiteDestroyHostedService) TestOkayWhenHostedServiceNotFoundWhenDeleting(c *C) {
 
516
    var responses []DispatcherResponse
 
517
    // Prepare.
 
518
    responses = append(responses, makeOKXMLResponse(c, exampleHostedService)...)
 
519
    // Someone else has destroyed the deployments in the meantime.
 
520
    responses = append(responses, exampleNotFoundResponse, exampleNotFoundResponse)
 
521
    // Someone else has destroyed the hosted service in the meantime.
 
522
    responses = append(responses, exampleNotFoundResponse)
 
523
    record := []*X509Request{}
 
524
    rigRecordingPreparedResponseDispatcher(&record, responses)
 
525
    // Exercise DestroyHostedService.
 
526
    api := makeAPI(c)
 
527
    request := &DestroyHostedServiceRequest{ServiceName: "service-name"}
 
528
    err := api.DestroyHostedService(request)
 
529
    c.Assert(err, IsNil)
 
530
    c.Check(record, HasLen, 4)
 
531
    assertGetDeploymentRequest(c, api, &GetDeploymentRequest{
 
532
        request.ServiceName, "one"}, record[1])
 
533
    assertGetDeploymentRequest(c, api, &GetDeploymentRequest{
 
534
        request.ServiceName, "two"}, record[2])
 
535
    assertDeleteHostedServiceRequest(c, api, request.ServiceName, record[3])
 
536
}
 
537
 
 
538
func (suite *suiteDestroyHostedService) TestFailsGettingHostedService(c *C) {
 
539
    var responses []DispatcherResponse
 
540
    // Prepare.
 
541
    responses = []DispatcherResponse{exampleFailResponse}
 
542
    record := []*X509Request{}
 
543
    rigRecordingPreparedResponseDispatcher(&record, responses)
 
544
    // Exercise DestroyHostedService.
 
545
    api := makeAPI(c)
 
546
    request := &DestroyHostedServiceRequest{ServiceName: "service-name"}
 
547
    err := api.DestroyHostedService(request)
 
548
    c.Assert(err, NotNil)
 
549
    c.Check(err, ErrorMatches, "GET request failed [(]500: Internal Server Error[)]")
 
550
    c.Check(record, HasLen, 1)
 
551
}
 
552
 
 
553
func (suite *suiteDestroyHostedService) TestFailsDestroyingDeployment(c *C) {
 
554
    var responses []DispatcherResponse
 
555
    // Prepare.
 
556
    responses = append(responses, makeOKXMLResponse(c, exampleHostedService)...)
 
557
    responses = append(responses, exampleFailResponse)
 
558
    record := []*X509Request{}
 
559
    rigRecordingPreparedResponseDispatcher(&record, responses)
 
560
    // Exercise DestroyHostedService.
 
561
    api := makeAPI(c)
 
562
    request := &DestroyHostedServiceRequest{ServiceName: "service-name"}
 
563
    err := api.DestroyHostedService(request)
 
564
    c.Assert(err, NotNil)
 
565
    c.Check(err, ErrorMatches, "GET request failed [(]500: Internal Server Error[)]")
 
566
    c.Check(record, HasLen, 2)
 
567
}
 
568
 
 
569
func (suite *suiteDestroyHostedService) TestFailsDeletingHostedService(c *C) {
 
570
    var responses []DispatcherResponse
 
571
    // Prepare.
 
572
    responses = append(responses, makeOKXMLResponse(c, exampleHostedService)...)
 
573
    // Deployments not found, but that's okay.
 
574
    responses = append(responses, exampleNotFoundResponse, exampleNotFoundResponse)
 
575
    // When deleting hosted service.
 
576
    responses = append(responses, exampleFailResponse)
 
577
    record := []*X509Request{}
 
578
    rigRecordingPreparedResponseDispatcher(&record, responses)
 
579
    // Exercise DestroyHostedService.
 
580
    api := makeAPI(c)
 
581
    request := &DestroyHostedServiceRequest{ServiceName: "service-name"}
 
582
    err := api.DestroyHostedService(request)
 
583
    c.Assert(err, NotNil)
 
584
    c.Check(err, ErrorMatches, "DELETE request failed [(]500: Internal Server Error[)]")
 
585
    c.Check(record, HasLen, 4)
 
586
}