Skip to content

Commit

Permalink
Add Procmanager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 18, 2019
1 parent 073408f commit 437ee36
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/app2/appserver/proc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

var (
errAppAlreadyExists = errors.New("app already exists")
errNoSuchApp = errors.New("no such app")
)

// ProcManager allows to manage skywire applications.
Expand Down Expand Up @@ -117,7 +118,7 @@ func (m *ProcManager) pop(name string) (*Proc, error) {

p, ok := m.procs[name]
if !ok {
return nil, errors.New("no such app")
return nil, errNoSuchApp
}

delete(m.procs, name)
Expand Down
63 changes: 63 additions & 0 deletions pkg/app2/appserver/proc_manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package appserver

import (
"sort"
"testing"

"github.com/stretchr/testify/require"

"github.com/skycoin/skycoin/src/util/logging"
)

func TestProcManager_Exists(t *testing.T) {
m := NewProcManager(logging.MustGetLogger("proc_manager"))

appName := "app"

ok := m.Exists(appName)
require.False(t, ok)

m.procs[appName] = nil

ok = m.Exists(appName)
require.True(t, ok)
}

func TestProcManager_Range(t *testing.T) {
m := NewProcManager(logging.MustGetLogger("proc_manager"))

wantAppNames := []string{"app1", "app2", "app3"}

for _, n := range wantAppNames {
m.procs[n] = nil
}

var gotAppNames []string
next := func(name string, app *Proc) bool {
gotAppNames = append(gotAppNames, name)
require.Nil(t, app)
return true
}

m.Range(next)

sort.Strings(gotAppNames)
require.Equal(t, gotAppNames, wantAppNames)
}

func TestProcManager_Pop(t *testing.T) {
m := NewProcManager(logging.MustGetLogger("proc_manager"))

appName := "app"

app, err := m.pop(appName)
require.Equal(t, err, errNoSuchApp)

m.procs[appName] = nil

app, err = m.pop(appName)
require.NoError(t, err)
require.Nil(t, app)
_, ok := m.procs[appName]
require.False(t, ok)
}

0 comments on commit 437ee36

Please sign in to comment.