Skip to content

Commit

Permalink
Write tests. Fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Oct 21, 2014
1 parent 2b9318c commit f3cafa3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gosh.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func mkScriptChans(dir string) (map[string]chan string, map[string]string, error
chs := map[string]chan string{}
cmdMap := map[string]string{} // URL path -> filesystem path

scripts, err := findScripts(flag.Arg(0))
scripts, err := findScripts(dir)
if err != nil {
return nil, nil, err
}

for _, n := range scripts {
chs[n] = make(chan string, 1)
cmdMap[n] = filepath.Join(flag.Arg(0), n)
cmdMap[n] = filepath.Join(dir, n)
}
return chs, cmdMap, nil
}
Expand Down
45 changes: 45 additions & 0 deletions gosh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,51 @@ func TestFindScripts(t *testing.T) {
}
}

func TestMkScriptChans(t *testing.T) {
t.Parallel()

m1, m2, err := mkScriptChans("tmp/test-find-non-existent")
if err == nil {
t.Errorf("Failed to fail to find missing scripts, got %v / %v", m1, m2)
}

os.MkdirAll("tmp/test-mkscr", 0777)
names := []string{"script1", "script2", "script3"}
defer os.RemoveAll("tmp/test-mkscr")
for _, fn := range names {
err := ioutil.WriteFile("tmp/test-mkscr/"+fn, nil, 0755)
if err != nil {
t.Fatalf("Can't create test script.")
}
}

chans, chanmap, err := mkScriptChans("tmp/test-mkscr")
if err != nil {
t.Fatalf("Failed to find missing scripts, got %v", err)
}
if len(chans) != len(chanmap) {
t.Errorf("Huh? %v %v", chans, chanmap)
}
expmap := map[string]string{
"script1": "tmp/test-mkscr/script1",
"script2": "tmp/test-mkscr/script2",
"script3": "tmp/test-mkscr/script3",
}
if len(chanmap) != len(expmap) {
t.Errorf("chanmap != expmap: %v, %v", chanmap, expmap)
}

for k, v := range expmap {
got := chanmap[k]
if got != v {
t.Errorf("Error on %q, wanted %q, got %q", k, v, got)
}
if _, ok := chans[k]; !ok {
t.Errorf("No corresponding channel for %q", k)
}
}
}

func TestRunner(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit f3cafa3

Please sign in to comment.