JustBeforeEach(func() { fakeDriver = new(voldriverfakes.FakeDriver) fakeDriver.ActivateReturns(voldriver.ActivateResponse{ Implements: []string{"VolumeDriver"}, }) fakeRemoteClientFactory.NewRemoteClientReturns(fakeDriver, nil) }) It(it, func() { drivers, err := driverSyncer.Discover(logger) Expect(err).ToNot(HaveOccurred()) Expect(len(drivers)).To(Equal(1)) Expect(fakeRemoteClientFactory.NewRemoteClientCallCount()).To(Equal(1)) Expect(fakeRemoteClientFactory.NewRemoteClientArgsForCall(0)).To(Equal(expected)) }) }) } TestCanonicalization("with an ip (and no port)", "127.0.0.1", "should return a canonicalized address", "http://127.0.0.1") TestCanonicalization("with an ip and port", "127.0.0.1:8080", "should return a canonicalized address", "http://127.0.0.1:8080") TestCanonicalization("with a tcp protocol uri with port", "tcp://127.0.0.1:8080", "should return a canonicalized address", "http://127.0.0.1:8080") TestCanonicalization("with a tcp protocol uri without port", "tcp://127.0.0.1", "should return a canonicalized address", "http://127.0.0.1") TestCanonicalization("with a unix address including protocol", "unix:///other.sock", "should return a canonicalized address", "unix:///other.sock") TestCanonicalization("with a unix address missing its protocol", "/other.sock", "should return a canonicalized address", "/other.sock") Context("with an invalid url", func() { BeforeEach(func() { err := voldriver.WriteDriverSpec(logger, defaultPluginsDirectory, driverName, "spec", []byte("htt%p:\\\\")) Expect(err).NotTo(HaveOccurred())
localDriver = new(voldriverfakes.FakeDriver) fakeRemoteClientFactory.NewRemoteClientReturns(localDriver, nil) driverFactory = vollocal.NewDriverFactoryWithRemoteClientFactory(fakeRemoteClientFactory) }) Context("when a json driver spec is discovered", func() { BeforeEach(func() { err := voldriver.WriteDriverSpec(testLogger, defaultPluginsDirectory, driverName, "json", []byte("{\"Addr\":\"http://0.0.0.0:8080\"}")) Expect(err).NotTo(HaveOccurred()) driver, err = driverFactory.Driver(testLogger, driverName, defaultPluginsDirectory, driverName+".json") Expect(err).ToNot(HaveOccurred()) }) It("should return the correct driver", func() { Expect(driver).To(Equal(localDriver)) Expect(fakeRemoteClientFactory.NewRemoteClientArgsForCall(0)).To(Equal("http://0.0.0.0:8080")) }) It("should fail if unable to open file", func() { fakeOs := new(os_fake.FakeOs) driverFactory := vollocal.NewDriverFactoryWithOs(fakeOs) fakeOs.OpenReturns(nil, fmt.Errorf("error opening file")) _, err := driverFactory.Driver(testLogger, driverName, defaultPluginsDirectory, driverName+".json") Expect(err).To(HaveOccurred()) }) }) Context("when an invalid json spec is discovered", func() { BeforeEach(func() { err := voldriver.WriteDriverSpec(testLogger, defaultPluginsDirectory, driverName, "json", []byte("{\"invalid\"}")) Expect(err).NotTo(HaveOccurred()) })