File: factory_test.go

package info (click to toggle)
golang-github-mesos-mesos-go 0.0.2+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 3,964 kB
  • ctags: 6,435
  • sloc: makefile: 18
file content (59 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package detector

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

type testDetector string

func (d testDetector) Start() error                 { return nil }
func (d testDetector) Detect(f MasterChanged) error { return nil }

func (d testDetector) Done() <-chan struct{} { return make(<-chan struct{}) }
func (d testDetector) Cancel()               {}

// unregister a factory plugin according to its prefix.
// this is part of the testing module on purpose: during normal execution there
// should be no need to dynamically unregister plugins.
func Unregister(prefix string) {
	pluginLock.Lock()
	defer pluginLock.Unlock()
	delete(plugins, prefix)
}

func TestDetectorFactoryRegister(t *testing.T) {
	prefix := "bbm:"
	Register(prefix, func(spec string) (Master, error) {
		return testDetector("Hello!"), nil
	})
	defer Unregister(prefix)

	f, ok := MatchingPlugin(prefix)

	assert.True(t, ok)
	assert.NotNil(t, f)
}

func TestDectorFactoryNew_EmptySpec(t *testing.T) {
	assert := assert.New(t)
	m, err := New("")
	assert.NotNil(err)
	assert.Nil(m)
}

func TestDectorFactoryNew_InvalidSpec(t *testing.T) {
	assert := assert.New(t)
	m, err := New("localhost")
	assert.NotNil(err)
	assert.Nil(m)
}

func TestDectorFactoryNew_TrivialSpec(t *testing.T) {
	assert := assert.New(t)
	m, err := New("localhost:1")
	assert.NoError(err)
	assert.NotNil(m)
	assert.IsType(&Standalone{}, m)
}