Permalink
Browse files

Move test helpers around, start implementing ParseConfig

  • Loading branch information...
1 parent 582f8d6 commit 1d3bd7725c29729643e3a8d408a8bfe5e70b5255 @mrnugget committed Mar 26, 2013
Showing with 59 additions and 9 deletions.
  1. +11 −0 all_test.go
  2. +11 −0 config.go
  3. +12 −0 config_test.go
  4. +0 −7 dir_watcher_test.go
  5. +8 −0 fixtures/example_config.json
  6. +17 −2 watchgopher.go
View
@@ -0,0 +1,11 @@
+package main
+
+import (
+ "path/filepath"
+ "runtime"
+)
+
+var (
+ _, filename, _, _ = runtime.Caller(0)
+ fixtures = filepath.Dir(filename) + "/fixtures"
+)
View
@@ -0,0 +1,11 @@
+package main
+
+type Rule struct {
+ Path string
+ Run string
+}
+
+func ParseConfig(path string) (rules []*Rule, err error) {
+ rules = make([]*Rule, 0)
+ return
+}
View
@@ -0,0 +1,12 @@
+package main
+
+import (
+ "testing"
+)
+
+func TestParseConfig(t *testing.T) {
+ _, err := ParseConfig(fixtures + "/example_config.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+}
View
@@ -3,17 +3,10 @@ package main
import (
"io/ioutil"
"os"
- "path/filepath"
- "runtime"
"testing"
"time"
)
-var (
- _, filename, _, _ = runtime.Caller(0)
- fixtures = filepath.Dir(filename) + "/fixtures"
-)
-
func TestEvents(t *testing.T) {
sub1 := fixtures + "/sub1"
sub2 := fixtures + "/sub2"
@@ -0,0 +1,8 @@
+{
+ "/tmp/foo": {
+ "run": "/usr/local/bar/foobar"
+ },
+ "/tmp/bar": {
+ "run": "/usr/local/bar/foobar"
+ }
+}
View
@@ -1,12 +1,27 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
func main() {
- // @TODO: Read configuration file either from `~/.watchgopher` or from
- // first command line argument
+ flag.Parse()
+ configPath := flag.Arg(0)
+ _, err := os.Stat(configPath)
+ if err != nil && os.IsNotExist(err) {
+ fmt.Println("Please pass the path to the config file to watchgopher")
+ os.Exit(1)
+ }
// @TODO: Parse configuration file to get which directories to watch,
// which pattern to match for which directory, which scripts to run on
// event
+ _, err = ParseConfig(configPath)
+ if err != nil {
+ fmt.Println("Error: Could not parse config file")
+ }
// @TODO: Watch directories for events (see `dir_watcher.go`) and pass
// events to a manager, which checks for appliance of configuration

0 comments on commit 1d3bd77

Please sign in to comment.