github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v6/shared/noaa_client_test.go (about) 1 package shared_test 2 3 import ( 4 "reflect" 5 6 "code.cloudfoundry.org/cli/api/uaa" 7 "code.cloudfoundry.org/cli/command/commandfakes" 8 9 "code.cloudfoundry.org/cli/command/v6/shared" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("NewNOAAClient", func() { 15 When("a new NOAA client is created", func() { 16 var ( 17 fakeConfig *commandfakes.FakeConfig 18 testUI *commandfakes.FakeUI 19 uaaClient *uaa.Client 20 ) 21 22 BeforeEach(func() { 23 fakeConfig = new(commandfakes.FakeConfig) 24 testUI = new(commandfakes.FakeUI) 25 uaaClient = new(uaa.Client) 26 }) 27 28 It("always sets a token refresher", func() { 29 // We need to be sure that the token refresher is set on the NOAA client. 30 // However, this struct is in a library we don't control and the field iss 31 // private. Testing this functionality via an integration test would 32 // require the test to both wait for an OAuth token to expire and kill a 33 // TCP connection. Making a reflection-free unit test would require 34 // changing everywhere we pass around a consumer.Consumer to instead use 35 // an interface. 36 client := shared.NewNOAAClient("some-url", fakeConfig, uaaClient, testUI) 37 // This warning is expected. This access to ValueOf(*client) is not 38 // threadsafe, but we only have this local variable. 39 v := reflect.ValueOf(*client) // nolint: vet 40 refresher := v.FieldByName("tokenRefresher") 41 Expect(refresher.IsNil()).To(BeFalse(), "NewNOAAClient failed to call RefreshTokenFrom on NOAA client") 42 }) 43 }) 44 })