1717package rest
1818
1919import (
20+ drivermanager "github.com/IBM/ibm-storage-odf-block-driver/pkg/driver"
2021 "net/http"
2122 "testing"
2223)
@@ -27,6 +28,12 @@ var c = FSRestClient{PostRequester: &Requester{
2728 return []byte (body ), 200 , nil
2829 },
2930}}
31+ var manager1 = drivermanager.DriverManager {SystemName : "FS-system-name" }
32+ var config1 = Config {
33+ Host : "FS-Host" ,
34+ Username : "FS-Username" ,
35+ Password : "FS-Password" ,
36+ }
3037
3138func TestNormalizeVersion (t * testing.T ) {
3239
@@ -49,6 +56,24 @@ func TestNormalizeVersion(t *testing.T) {
4956 })
5057}
5158
59+ func TestIsHealth (t * testing.T ) {
60+ // Happy path
61+ t .Run ("health check state" , func (t * testing.T ) {
62+ res := c .isHealth ("completed" )
63+ if res != true {
64+ t .Errorf ("Health check should return true." )
65+ }
66+ })
67+
68+ // Unhappy path
69+ t .Run ("health check state" , func (t * testing.T ) {
70+ res := c .isHealth ("pending" )
71+ if res != false {
72+ t .Errorf ("Health check should return false." )
73+ }
74+ })
75+ }
76+
5277func TestUserRole (t * testing.T ) {
5378
5479 t .Run ("Check User Administrator" , func (t * testing.T ) {
@@ -115,3 +140,124 @@ func TestCheckFlashsystemClusterState(t *testing.T) {
115140 }
116141 })
117142}
143+
144+ func TestLssystem (t * testing.T ) {
145+ // Happy path
146+ t .Run ("run successful lssystem" , func (t * testing.T ) {
147+ body = `{"id": "0000020420E0E8DC", "name": "fab3p-159-c", "location": "local"}`
148+ _ , err := c .Lssystem ()
149+ if err != nil {
150+ t .Errorf ("lssystem check should return without error" )
151+ }
152+ })
153+
154+ // unhappy path
155+ t .Run ("run failed lssystem" , func (t * testing.T ) {
156+ body = ``
157+ _ , err := c .Lssystem ()
158+ if err == nil {
159+ t .Errorf ("lssystem check should return error " )
160+ }
161+ })
162+ }
163+
164+ func TestLsnode (t * testing.T ) {
165+ // Happy path
166+ t .Run ("run successful lsnode" , func (t * testing.T ) {
167+ body = `[{"name":"node1", "id":"1", "status":"online", "IO_group_name":"io_grp0"}]`
168+ _ , err := c .Lsnode ()
169+ if err != nil {
170+ t .Errorf ("lsnode check should return without error" )
171+ }
172+ })
173+
174+ // unhappy path
175+ t .Run ("run failed lsnode" , func (t * testing.T ) {
176+ body = ``
177+ _ , err := c .Lsnode ()
178+ if err == nil {
179+ t .Errorf ("lsnode check should return error" )
180+ }
181+ })
182+ }
183+
184+ func TestLssystemstats (t * testing.T ) {
185+ // Happy path
186+ t .Run ("run successful Lssystemstats" , func (t * testing.T ) {
187+ body = `[{"stat_name": "vdisk_r_mb", "stat_current": "5", "stat_peak": "0" ,"stat_peak_time": "210604162102"}]`
188+ _ , err := c .Lssystemstats ()
189+ if err != nil {
190+ t .Errorf ("Lssystemstats check should return without error" )
191+ }
192+ })
193+
194+ // unhappy path
195+ t .Run ("run failed Lssystemstats" , func (t * testing.T ) {
196+ body = ``
197+ _ , err := c .Lssystemstats ()
198+ if err == nil {
199+ t .Errorf ("Lssystemstats check should return error" )
200+ }
201+ })
202+ }
203+
204+ func TestLscurrentuser (t * testing.T ) {
205+ // Happy path
206+ t .Run ("run successful Lscurrentuser" , func (t * testing.T ) {
207+ body = `[{"name": "superuser", "role": "Administrator"}]`
208+ _ , err := c .Lscurrentuser ()
209+ if err != nil {
210+ t .Errorf ("Lscurrentuser check should return without error" )
211+ }
212+ })
213+
214+ // unhappy path
215+ t .Run ("run failed Lscurrentuser" , func (t * testing.T ) {
216+ body = ``
217+ _ , err := c .Lscurrentuser ()
218+ if err == nil {
219+ t .Errorf ("Lscurrentuser check should return error" )
220+ }
221+ })
222+ }
223+
224+ func TestLsmdiskgrp (t * testing.T ) {
225+ // Happy path
226+ t .Run ("run successful Lsmdiskgrp" , func (t * testing.T ) {
227+ body = `[{"id": "0", "name": "Pool0", "status": "online"}]`
228+ _ , err := c .Lsmdiskgrp ()
229+ if err != nil {
230+ t .Errorf ("Lsmdiskgrp check should return without error" )
231+ }
232+ })
233+
234+ // unhappy path
235+ t .Run ("run failed Lsmdiskgrp" , func (t * testing.T ) {
236+ body = ``
237+ _ , err := c .Lsmdiskgrp ()
238+ if err == nil {
239+ t .Errorf ("Lsmdiskgrp check should return error" )
240+ }
241+ })
242+ }
243+
244+ func TestNewFSRestClient (t * testing.T ) {
245+ // unHappy path
246+ t .Run ("run successful NewFSRestClient" , func (t * testing.T ) {
247+ _ , err := c .NewFSRestClient (config1 , & manager1 )
248+ if err == nil {
249+ t .Errorf ("NewFSRestClient check should return with error" )
250+ }
251+ })
252+ }
253+
254+ func TestRetryDo (t * testing.T ) {
255+ // Happy path
256+ t .Run ("run successful retryDo" , func (t * testing.T ) {
257+ body = `{"id": "0000020420E0E8DC", "name": "fab3p-159-c", "location": "local"}`
258+ _ , err := c .retryDo ("https://my-url" , "lssystem" )
259+ if err != nil {
260+ t .Errorf ("retryDo check should return without error" )
261+ }
262+ })
263+ }
0 commit comments