2016-11-05 17:09:05 -07:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
2016-12-01 16:10:46 -08:00
|
|
|
package node
|
2016-09-15 13:52:55 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
2016-09-28 09:59:01 -07:00
|
|
|
"time"
|
2016-09-15 13:52:55 -07:00
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
2016-10-26 00:38:39 +02:00
|
|
|
"github.com/rook/rook/pkg/model"
|
2016-10-27 13:26:25 +02:00
|
|
|
"github.com/rook/rook/pkg/rook/test"
|
2016-09-15 13:52:55 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestListNodes(t *testing.T) {
|
2016-10-27 13:26:25 +02:00
|
|
|
c := &test.MockRookRestClient{
|
2016-09-20 15:20:17 -07:00
|
|
|
MockGetNodes: func() ([]model.Node, error) {
|
|
|
|
|
nodes := []model.Node{
|
2016-09-28 09:59:01 -07:00
|
|
|
{
|
|
|
|
|
NodeID: "node1",
|
|
|
|
|
ClusterName: "cluster1",
|
2016-10-26 10:53:53 -07:00
|
|
|
PublicIP: "187.1.2.3",
|
|
|
|
|
PrivateIP: "10.0.0.100",
|
2016-09-28 09:59:01 -07:00
|
|
|
Storage: 100,
|
|
|
|
|
LastUpdated: time.Duration(1) * time.Second,
|
|
|
|
|
State: model.Healthy,
|
|
|
|
|
Location: "root=default,dc=datacenter5",
|
|
|
|
|
},
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
return nodes, nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := listNodes(c)
|
|
|
|
|
assert.Nil(t, err)
|
2016-10-27 11:11:54 -07:00
|
|
|
|
2016-12-02 16:57:41 -08:00
|
|
|
expectedOut := "PUBLIC PRIVATE STATE CLUSTER SIZE LOCATION UPDATED\n" +
|
2016-10-27 11:11:54 -07:00
|
|
|
"187.1.2.3 10.0.0.100 OK cluster1 100 B root=default,dc=datacenter5 1s ago \n"
|
|
|
|
|
assert.Equal(t, expectedOut, out)
|
2016-09-15 13:52:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestListNodesError(t *testing.T) {
|
2016-10-27 13:26:25 +02:00
|
|
|
c := &test.MockRookRestClient{
|
2016-09-20 15:20:17 -07:00
|
|
|
MockGetNodes: func() ([]model.Node, error) {
|
2016-09-15 13:52:55 -07:00
|
|
|
return nil, fmt.Errorf("mock get nodes failed")
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := listNodes(c)
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
assert.Equal(t, "", out)
|
|
|
|
|
}
|