@@ -3,6 +3,7 @@ package session
33import (
44 "fmt"
55 "github.com/jarcoal/httpmock"
6+ "github.com/softlayer/softlayer-go/datatypes"
67 "github.com/softlayer/softlayer-go/sl"
78 "os"
89 "strings"
@@ -176,3 +177,57 @@ func TestRefreshToken(t *testing.T) {
176177 }
177178 httpmock .Reset ()
178179}
180+
181+ func TestString (t * testing.T ) {
182+ // setup session and mock environment
183+ s = New ()
184+ s .Endpoint = restEndpoint
185+ s .IAMToken = "Bearer TestToken"
186+ s .IAMRefreshToken = "TestTokenRefresh"
187+ slOptions := & sl.Options {}
188+ slResults := & datatypes.Account {}
189+ // s.Debug = true
190+ httpmock .Activate ()
191+ defer httpmock .DeactivateAndReset ()
192+ fmt .Printf ("TestString [Happy Path]: " )
193+ expected := ""
194+ if s .String () != expected {
195+ t .Errorf ("%s != %s" , s .String (), expected )
196+ }
197+ // Happy Path
198+ httpmock .RegisterResponder ("GET" , fmt .Sprintf ("%s/SoftLayer_Account.json" , restEndpoint ),
199+ httpmock .NewStringResponder (200 , `{"id":123,"companyName":"test"}` ),
200+ )
201+ err := s .DoRequest ("SoftLayer_Account" , "getObject" , nil , slOptions , slResults )
202+ if err != nil {
203+ t .Errorf ("Testing Error: %v\n " , err .Error ())
204+ }
205+ expected = "SoftLayer_Account::getObject(id=0, mask='', filter='', )"
206+ if s .String () != expected {
207+ t .Errorf ("%s != %s" , s .String (), expected )
208+ }
209+
210+ // Test Setting args
211+ // httpmock.Reset()
212+ httpmock .RegisterResponder ("POST" , fmt .Sprintf ("%s/SoftLayer_Account/999.json" , restEndpoint ),
213+ httpmock .NewStringResponder (200 , `{"id":123,"companyName":"test"}` ),
214+ )
215+ fmt .Printf ("TestString [Happy Path with args]: " )
216+ slOptions = & sl.Options {
217+ Mask : "mask[id,companyName]" ,
218+ Filter : `{"id":{"operation":{123}}` ,
219+ Id : sl .Int (999 ),
220+ }
221+ args := []interface {}{
222+ sl .String ("https://example.com" ),
223+ }
224+ err = s .DoRequest ("SoftLayer_Account" , "getObject" , args , slOptions , slResults )
225+ if err != nil {
226+ t .Errorf ("Testing Error: %v\n " , err .Error ())
227+ }
228+ expected = `SoftLayer_Account::getObject(id=999, mask='mask[id,companyName]', filter='{"id":{"operation":{123}}', '{"parameters":["https://example.com"]}')`
229+ if s .String () != expected {
230+ t .Errorf ("%s != %s" , s .String (), expected )
231+ }
232+ httpmock .Reset ()
233+ }
0 commit comments