Esempio n. 1
0
	})

	AfterEach(func() {
		ginkgomon.Kill(process)
		err := os.RemoveAll(driversPath)
		Expect(err).NotTo(HaveOccurred())
	})

	It("should listen on the given address", func() {
		_, err := client.ListDrivers(testLogger)
		Expect(err).NotTo(HaveOccurred())
	})

	Context("given a driverspath with a single spec file", func() {
		BeforeEach(func() {
			err := voldriver.WriteDriverSpec(testLogger, driversPath, "test-driver", "spec", []byte(driverAddr))
			Expect(err).NotTo(HaveOccurred())

			resp, err := json.Marshal(voldriver.ActivateResponse{
				Implements: []string{"VolumeDriver"},
			})
			Expect(err).NotTo(HaveOccurred())
			fakeDriver.RouteToHandler("POST", "/Plugin.Activate",
				ghttp.RespondWith(200, resp),
			)

			resp, err = json.Marshal(voldriver.ListResponse{
				Volumes: []voldriver.VolumeInfo{},
			})
			Expect(err).NotTo(HaveOccurred())
			It("should report empty list of drivers", func() {
				drivers, err := client.ListDrivers(logger)
				Expect(err).NotTo(HaveOccurred())
				Expect(len(drivers.Drivers)).To(Equal(0))
			})

			AfterEach(func() {
				ginkgomon.Kill(process)
			})

		})

		Context("has driver in location", func() {
			BeforeEach(func() {
				err := voldriver.WriteDriverSpec(logger, defaultPluginsDirectory, "fakedriver", "spec", []byte("http://0.0.0.0:8080"))
				Expect(err).NotTo(HaveOccurred())

				driverSyncer = vollocal.NewDriverSyncerWithDriverFactory(logger, driverRegistry, []string{defaultPluginsDirectory}, scanInterval, fakeClock, fakeDriverFactory)
				client = vollocal.NewLocalClient(logger, driverRegistry, fakeClock)

				fakeDriver := new(voldriverfakes.FakeDriver)
				fakeDriverFactory.DriverReturns(fakeDriver, nil)

				fakeDriver.ActivateReturns(voldriver.ActivateResponse{Implements: []string{"VolumeDriver"}})
			})

			It("should report empty list of drivers", func() {
				drivers, err := client.ListDrivers(logger)
				Expect(err).NotTo(HaveOccurred())
				Expect(len(drivers.Drivers)).To(Equal(0))
			localDriver             *voldriverfakes.FakeDriver
			driver                  voldriver.Driver
			driverFactory           vollocal.DriverFactory
		)
		BeforeEach(func() {
			driverName = "some-driver-name"
			fakeRemoteClientFactory = new(voldriverfakes.FakeRemoteClientFactory)
			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())
			})
				drivers := registry.Drivers()
				Expect(len(drivers)).To(Equal(0))
				Expect(fakeDriverFactory.DriverCallCount()).To(Equal(0))
			})
		})

		Context("when there are drivers", func() {
			var (
				fakeDriver *voldriverfakes.FakeDriver
				driverName string
				syncer     vollocal.DriverSyncer
			)

			BeforeEach(func() {
				driverName = "fakedriver"
				err := voldriver.WriteDriverSpec(logger, defaultPluginsDirectory, driverName, "spec", []byte("http://0.0.0.0:8080"))
				Expect(err).NotTo(HaveOccurred())

				syncer = vollocal.NewDriverSyncerWithDriverFactory(logger, registry, []string{defaultPluginsDirectory}, scanInterval, fakeClock, fakeDriverFactory)

				fakeDriver = new(voldriverfakes.FakeDriver)
				fakeDriver.ActivateReturns(voldriver.ActivateResponse{
					Implements: []string{"VolumeDriver"},
				})

				fakeDriverFactory.DriverReturns(fakeDriver, nil)

				process = ginkgomon.Invoke(syncer.Runner())
			})

			AfterEach(func() {
	BeforeEach(func() {
		logger = lagertest.NewTestLogger("mount-purger")

		driverRegistry = vollocal.NewDriverRegistry()

		purger = vollocal.NewMountPurger(logger, driverRegistry)
	})

	It("should succeed when there are no drivers", func() {
		err := purger.PurgeMounts(logger)
		Expect(err).NotTo(HaveOccurred())
	})

	Context("when there is a driver", func() {
		BeforeEach(func() {
			err := voldriver.WriteDriverSpec(logger, defaultPluginsDirectory, "fakedriver", "spec", []byte("http://0.0.0.0:8080"))
			Expect(err).NotTo(HaveOccurred())

			fakeDriverFactory = new(volmanfakes.FakeDriverFactory)
			fakeClock = fakeclock.NewFakeClock(time.Unix(123, 456))

			scanInterval = 1 * time.Second

			driverSyncer = vollocal.NewDriverSyncerWithDriverFactory(logger, driverRegistry, []string{defaultPluginsDirectory}, scanInterval, fakeClock, fakeDriverFactory)
			client = vollocal.NewLocalClient(logger, driverRegistry, fakeClock)

			fakeDriver = new(voldriverfakes.FakeDriver)
			fakeDriverFactory.DriverReturns(fakeDriver, nil)

			fakeDriver.ActivateReturns(voldriver.ActivateResponse{Implements: []string{"VolumeDriver"}})