コード例 #1
0
ファイル: mount.go プロジェクト: koding/koding
func (m *Mount) unmount() (err error) {
	if m.Unmounter != nil {
		err = m.Unmounter.Unmount()
	} else {
		err = fuseklient.Unmount(m.LocalPath)
	}

	// Ignoring this error, since this fails when it's unable to find mount on
	// path, ie. we're already at the desired state we want to be in.
	if err != nil {
		m.Log.Warning("Mount#Unmount on %s failed: %s...ignoring error.", m.LocalPath, err)
	}

	return nil
}
コード例 #2
0
func TestDeviceNotConfiguredRepair(t *testing.T) {
	SkipConvey("", t, func() {
		tmpDir, err := ioutil.TempDir("", "devicenotconfiguredrepair")
		So(err, ShouldBeNil)
		defer os.RemoveAll(tmpDir)

		mountDir := filepath.Join(tmpDir, "mount")
		So(os.Mkdir(mountDir, 0755), ShouldBeNil)

		fakeKlient := &testutil.FakeKlient{
			ReturnMountInfo: req.MountInfoResponse{
				MountFolder: req.MountFolder{
					LocalPath: mountDir,
				},
			},
		}

		r := &DeviceNotConfiguredRepair{
			Log:    discardLogger,
			Stdout: util.NewFprint(ioutil.Discard),
			Klient: fakeKlient,
		}

		Convey("Given a normal dir", func() {
			Convey("When Status() is called", func() {
				Convey("It should return okay", func() {
					ok, err := r.Status()
					So(err, ShouldBeNil)
					So(ok, ShouldBeTrue)
				})
			})
		})

		Convey("Given a DeviceNotConfigured dir", func() {
			err = MakeDirDeviceNotConfigured(mountDir)
			So(err, ShouldBeNil)
			defer fuseklient.Unmount(mountDir)

			Convey("When Status() is called", func() {
				Convey("It should return not okay", func() {
					ok, err := r.Status()
					So(ok, ShouldBeFalse)
					So(err, ShouldBeNil)
				})
			})

			Convey("When Repair() is called", func() {
				Convey("It should call RemoteRemount", func() {
					// Ignoring the error, because it's going to return the status error anyway.
					r.Repair()
					So(fakeKlient.GetCallCount("RemoteRemount"), ShouldEqual, 1)
				})

				Convey("It should run status again", func() {
					err := r.Repair()
					So(err, ShouldNotBeNil)
					So(err.Error(), ShouldContainSubstring, "not-okay")
				})
			})
		})
	})

}