github.com/dims/containerd@v0.2.5/supervisor/sort_test.go (about)

     1  package supervisor
     2  
     3  import (
     4  	"flag"
     5  	"os"
     6  	"sort"
     7  	"testing"
     8  
     9  	"github.com/docker/containerd/runtime"
    10  	"github.com/docker/containerd/specs"
    11  )
    12  
    13  var (
    14  	runtimeTool = flag.String("runtime", "runc", "Runtime to use for this test")
    15  )
    16  
    17  type testProcess struct {
    18  	id string
    19  }
    20  
    21  func (p *testProcess) ID() string {
    22  	return p.id
    23  }
    24  
    25  func (p *testProcess) Start() error {
    26  	return nil
    27  }
    28  
    29  func (p *testProcess) CloseStdin() error {
    30  	return nil
    31  }
    32  
    33  func (p *testProcess) Resize(w, h int) error {
    34  	return nil
    35  }
    36  
    37  func (p *testProcess) Stdio() runtime.Stdio {
    38  	return runtime.Stdio{}
    39  }
    40  
    41  func (p *testProcess) SystemPid() int {
    42  	return -1
    43  }
    44  
    45  func (p *testProcess) ExitFD() int {
    46  	return -1
    47  }
    48  
    49  func (p *testProcess) ExitStatus() (uint32, error) {
    50  	return runtime.UnknownStatus, nil
    51  }
    52  
    53  func (p *testProcess) Container() runtime.Container {
    54  	return nil
    55  }
    56  
    57  func (p *testProcess) Spec() specs.ProcessSpec {
    58  	return specs.ProcessSpec{}
    59  }
    60  
    61  func (p *testProcess) Signal(os.Signal) error {
    62  	return nil
    63  }
    64  
    65  func (p *testProcess) Close() error {
    66  	return nil
    67  }
    68  
    69  func (p *testProcess) State() runtime.State {
    70  	return runtime.Running
    71  }
    72  
    73  func (p *testProcess) Wait() {
    74  }
    75  
    76  func TestSortProcesses(t *testing.T) {
    77  	p := []runtime.Process{
    78  		&testProcess{"ls"},
    79  		&testProcess{"other"},
    80  		&testProcess{"init"},
    81  		&testProcess{"other2"},
    82  	}
    83  	s := &processSorter{p}
    84  	sort.Sort(s)
    85  
    86  	if id := p[len(p)-1].ID(); id != "init" {
    87  		t.Fatalf("expected init but received %q", id)
    88  	}
    89  }