}
type NodeStatus struct {
- Volumes map[string]*VolumeStatus `json:"volumes"`
+ Volumes []*VolumeStatus `json:"volumes"`
}
func StatusHandler(w http.ResponseWriter, req *http.Request) {
// Returns a NodeStatus struct describing this Keep
// node's current status.
//
-func GetNodeStatus() NodeStatus {
+func GetNodeStatus() *NodeStatus {
st := new(NodeStatus)
- st.Volumes = make(map[string]*VolumeStatus)
- for _, vol := range KeepVolumes {
- st.Volumes[vol] = GetVolumeStatus(vol)
+ st.Volumes = make([]*VolumeStatus, len(KeepVolumes))
+ for i, vol := range KeepVolumes {
+ st.Volumes[i] = GetVolumeStatus(vol)
}
return st
}
// - use an interface to mock ioutil.TempFile with a File
// object that always returns an error on write
//
-// * TestNodeStatus
-// - test that GetNodeStatus returns a structure with expected
-// values: need to mock FreeDiskSpace or Statfs, or use a tmpfs
-//
// ========================================
// GetBlock tests.
// ========================================
}
}
+// TestNodeStatus
+// Test that GetNodeStatus returns valid info about available volumes.
+//
+// TODO(twp): set up appropriate interfaces to permit more rigorous
+// testing.
+//
+func TestNodeStatus(t *testing.T) {
+ defer teardown()
+
+ // Set up test Keep volumes.
+ KeepVolumes = setup(t, 2)
+
+ // Get node status and make a basic sanity check.
+ st := GetNodeStatus()
+ for i, vol := range KeepVolumes {
+ volinfo := st.Volumes[i]
+ mtp := volinfo.MountPoint
+ if mtp != vol {
+ t.Errorf("GetNodeStatus mount_point %s != KeepVolume %s", mtp, vol)
+ }
+ if volinfo.BytesFree == 0 {
+ t.Errorf("uninitialized bytes_free in %v", volinfo)
+ }
+ if volinfo.BytesUsed == 0 {
+ t.Errorf("uninitialized bytes_used in %v", volinfo)
+ }
+ }
+}
+
// ========================================
// Helper functions for unit tests.
// ========================================