adding error output to NewInformerWithMetric

This commit is contained in:
dgrisham 2017-09-01 09:47:48 -06:00
parent 32984611ec
commit 456603f7a8
3 changed files with 11 additions and 9 deletions

View File

@ -54,15 +54,15 @@ func NewInformer(name string) *Informer {
// NewInformerWithMetric returns an Informer that uses the input MetricType. The
// name argument has the same purpose as in NewInformer.
func NewInformerWithMetric(metric MetricType, name string) *Informer {
func NewInformerWithMetric(metric MetricType, name string) (*Informer, error) {
// check whether specified metric is supported
if rpc, valid := metricToRPC[metric]; valid {
return &Informer{
name: name,
rpcName: rpc,
}
}, nil
}
return nil
return nil, fmt.Error("Error creating Informer: invalid MetricType")
}
// Name returns the user-facing name of this informer.

View File

@ -73,8 +73,8 @@ func Test(t *testing.T) {
}
func TestFreeSpace(t *testing.T) {
inf := NewInformerWithMetric(MetricFreeSpace, "disk-freespace")
if inf == nil {
inf, err := NewInformerWithMetric(MetricFreeSpace, "disk-freespace")
if err != nil {
t.Error("informer not initialized properly")
}
defer inf.Shutdown()
@ -94,8 +94,8 @@ func TestFreeSpace(t *testing.T) {
}
func TestRepoSize(t *testing.T) {
inf := NewInformerWithMetric(MetricRepoSize, "disk-reposize")
if inf == nil {
inf, err := NewInformerWithMetric(MetricRepoSize, "disk-reposize")
if err != nil {
t.Error("informer not initialized properly")
}
defer inf.Shutdown()

View File

@ -349,10 +349,12 @@ func setupAllocation(name string) (ipfscluster.Informer, ipfscluster.PinAllocato
name = "disk-freespace"
fallthrough
case "disk-freespace":
informer := disk.NewInformerWithMetric(disk.MetricFreeSpace, name)
informer, err := disk.NewInformerWithMetric(disk.MetricFreeSpace, name)
checkErr("Setting up allocation strategy", err)
return informer, descendalloc.NewAllocator()
case "disk-reposize":
informer := disk.NewInformerWithMetric(disk.MetricRepoSize, name)
informer, err := disk.NewInformerWithMetric(disk.MetricRepoSize, name)
checkErr("Setting up allocation strategy", err)
return informer, ascendalloc.NewAllocator()
case "numpin", "pincount":
informer := numpin.NewInformer()