Added rudimentary GetNodeStatus test. (refs #2561)
authorTim Pierce <twp@curoverse.com>
Mon, 14 Apr 2014 19:54:26 +0000 (15:54 -0400)
committerTim Pierce <twp@curoverse.com>
Mon, 14 Apr 2014 19:54:26 +0000 (15:54 -0400)
Added GetNodeStatus unit test.
Revised structure of NodeStatus struct to reflect the desired output format.

services/keep/keep.go
services/keep/keep_test.go

index 6906610918ab3ff1c1aa8bfa660dc59c1832aa36..7323c8925328b3cfa2ebdd8f9f1af54ec31df6b9 100644 (file)
@@ -241,7 +241,7 @@ type VolumeStatus struct {
 }
 
 type NodeStatus struct {
-       Volumes map[string]*VolumeStatus `json:"volumes"`
+       Volumes []*VolumeStatus `json:"volumes"`
 }
 
 func StatusHandler(w http.ResponseWriter, req *http.Request) {
@@ -259,12 +259,12 @@ 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
 }
index 508e0cd5a07c86792f32756479feb159fee0f3ba..05eb410dd6c7c98db8f10cb434ba36a37d264170 100644 (file)
@@ -37,10 +37,6 @@ var BAD_BLOCK = []byte("The magic words are squeamish ossifrage.")
 //           - 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.
 // ========================================
@@ -320,6 +316,35 @@ func TestIndex(t *testing.T) {
        }
 }
 
+// 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.
 // ========================================