8 func TestOpenAndReadAllFail(t *testing.T) {
9 log_chan := make(chan string)
12 if x, err := OpenAndReadAll("/nonexistent/file", log_chan); err == nil {
13 t.Fatalf("Expected error, got %v", x)
16 if _, ok := <-log_chan; !ok {
17 t.Fatalf("Expected error message about nonexistent file")
19 if msg, ok := <-log_chan; ok {
20 t.Fatalf("Expected channel to close, got %s", msg)
24 func TestOpenAndReadAllSuccess(t *testing.T) {
25 log_chan := make(chan string)
28 data, err := OpenAndReadAll("./crunchstat_test.go", log_chan)
30 t.Fatalf("got error %s", err)
32 if matched, err := regexp.MatchString("^package main\n", string(data)); err != nil || !matched {
33 t.Fatalf("data failed regexp: %s", err)
36 if msg, ok := <-log_chan; ok {
37 t.Fatalf("Expected channel to close, got %s", msg)