Ejemplo n.º 1
0
func main() {
	watchDir, targetDir := "tmp/source", "tmp/target"

	godotenv.Load(".env")

	fm, err := fm.NewFM("mms_prod")
	if err != nil {
		panic(err)
	}
	defer fm.Destroy()

	fm.Watch(watchDir, targetDir)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		<-c
		fmt.Println("Bye Bye")
		fm.Destroy()
		os.Exit(0)
	}()

	quit := make(chan bool, 1)
	/*
		for {
			fmt.Println("sleeping...")
			time.Sleep(10 * time.Second) // or runtime.Gosched() or similar per @misterbee
		}
	*/
	<-quit
}
    target: 'tmp/target2'
`,
			}

			for _, datum := range data {
				file, err := ioutil.TempFile("/tmp", "file_manager")
				if err != nil {
					Fail(fmt.Sprintf("Unable to create temp config file: %v", err))
				}

				if _, err = file.WriteString(datum); err != nil {
					Fail(fmt.Sprintf("Unable to write to temp config file: %v", err))
				}

				dropDB()
				fileManager, err = fm.NewFM(dbName, file.Name())

				if fileManager != nil {
					defer func() {
						fileManager.Destroy()
						fileManager = nil
					}()
				}

				os.Remove(file.Name())

				Ω(fileManager).Should(BeNil())
				Ω(err).Should(HaveOccurred())
			}
		})
		It("must watch directories from config", func() {