github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/deisctl/backend/fleet/list_unit_files_test.go (about)

     1  package fleet
     2  
     3  import (
     4  	"bytes"
     5  	"sync"
     6  	"testing"
     7  	"text/tabwriter"
     8  
     9  	"github.com/coreos/fleet/machine"
    10  	"github.com/coreos/fleet/schema"
    11  )
    12  
    13  func TestListUnitFiles(t *testing.T) {
    14  	t.Parallel()
    15  
    16  	testUnits := []*schema.Unit{
    17  		&schema.Unit{
    18  			Name:         "deis-controller.service",
    19  			DesiredState: "launched",
    20  			CurrentState: "launched",
    21  			MachineID:    "123456",
    22  			Options: []*schema.UnitOption{
    23  				&schema.UnitOption{
    24  					Section: "Unit",
    25  					Name:    "Description",
    26  					Value:   "deis-controller",
    27  				},
    28  			},
    29  		},
    30  		&schema.Unit{
    31  			Name:         "deis-router@1.service",
    32  			DesiredState: "launched",
    33  			CurrentState: "launched",
    34  			MachineID:    "654321",
    35  			Options: []*schema.UnitOption{
    36  				&schema.UnitOption{
    37  					Section: "Unit",
    38  					Name:    "Description",
    39  					Value:   "deis-router@1",
    40  				},
    41  			},
    42  		},
    43  	}
    44  
    45  	testMachines := []machine.MachineState{
    46  		machine.MachineState{
    47  			ID:       "123456",
    48  			PublicIP: "1.1.1.1",
    49  			Metadata: nil,
    50  			Version:  "",
    51  		},
    52  		machine.MachineState{
    53  			ID:       "654321",
    54  			PublicIP: "2.2.2.2",
    55  			Metadata: nil,
    56  			Version:  "",
    57  		},
    58  	}
    59  
    60  	testWriter := bytes.Buffer{}
    61  	testTabWriter := new(tabwriter.Writer)
    62  	testTabWriter.Init(&testWriter, 0, 8, 1, '\t', 0)
    63  
    64  	c := &FleetClient{Fleet: &stubFleetClient{testUnits: testUnits,
    65  		testMachineStates: testMachines, unitsMutex: &sync.Mutex{}},
    66  		out: testTabWriter}
    67  
    68  	err := c.ListUnitFiles()
    69  
    70  	if err != nil {
    71  		t.Fatal(err)
    72  	}
    73  
    74  	expected := `UNIT			HASH	DSTATE		STATE		TMACHINE
    75  deis-controller.service	61030e3	launched	launched	123456.../1.1.1.1
    76  deis-router@1.service	1182ecf	launched	launched	654321.../2.2.2.2
    77  `
    78  
    79  	actual := testWriter.String()
    80  
    81  	if expected != actual {
    82  		t.Errorf("Expected '%s', Got '%s'", expected, actual)
    83  	}
    84  }