adding error output to NewInformerWithMetric
This commit is contained in:
parent
32984611ec
commit
456603f7a8
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user