github.com/greenboxal/deis@v1.12.1/deisctl/backend/fleet/destroy_test.go (about)

     1  package fleet
     2  
     3  import (
     4  	"sync"
     5  	"testing"
     6  
     7  	"github.com/coreos/fleet/schema"
     8  )
     9  
    10  func TestDestroy(t *testing.T) {
    11  	t.Parallel()
    12  
    13  	testUnits := []*schema.Unit{
    14  		&schema.Unit{
    15  			Name: "deis-registry.service",
    16  		},
    17  		&schema.Unit{
    18  			Name: "deis-builder.service",
    19  		},
    20  		&schema.Unit{
    21  			Name: "deis-router@1.service",
    22  		},
    23  	}
    24  
    25  	testFleetClient := stubFleetClient{testUnits: testUnits, testUnitStates: []*schema.UnitState{}, unitsMutex: &sync.Mutex{}, unitStatesMutex: &sync.Mutex{}}
    26  
    27  	c := &FleetClient{Fleet: &testFleetClient}
    28  
    29  	var errOutput string
    30  	var wg sync.WaitGroup
    31  
    32  	logMutex := sync.Mutex{}
    33  
    34  	oe := newOutErr()
    35  	c.Destroy([]string{"controller", "registry", "router@1"}, &wg, oe.out, oe.ew)
    36  
    37  	wg.Wait()
    38  
    39  	logMutex.Lock()
    40  	if errOutput != "" {
    41  		t.Fatal(errOutput)
    42  	}
    43  	logMutex.Unlock()
    44  
    45  	if len(testFleetClient.testUnits) != 1 || testFleetClient.testUnits[0].Name != "deis-builder.service" {
    46  		t.Errorf("Got %d Units (want 1), first unit %s (want builder)", len(testFleetClient.testUnits), testFleetClient.testUnits[0].Name)
    47  	}
    48  }