github.com/georgethebeatle/containerd@v0.2.5/supervisor/supervisor_test.go (about) 1 package supervisor 2 3 import ( 4 "encoding/json" 5 "io/ioutil" 6 "os" 7 "path/filepath" 8 "testing" 9 "time" 10 11 "github.com/docker/containerd/runtime" 12 ) 13 14 func TestEventLogCompat(t *testing.T) { 15 tmpDir, err := ioutil.TempDir("", "") 16 if err != nil { 17 t.Errorf("Failed to create temp dir: %v", err) 18 } 19 20 path := filepath.Join(tmpDir, "events.log") 21 eventf, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_TRUNC, 0755) 22 if err != nil { 23 t.Errorf("Failed to create event logs: %v", err) 24 } 25 26 s := &Supervisor{stateDir: tmpDir} 27 28 enc := json.NewEncoder(eventf) 29 for _, ev := range []eventV1{ 30 { 31 Event: Event{ 32 ID: "abc", 33 Type: "event", 34 Timestamp: time.Now(), 35 PID: "42", 36 }, 37 Status: -1, 38 }, 39 { 40 Event: Event{ 41 ID: "abc", 42 Type: "event", 43 Timestamp: time.Now(), 44 PID: "42", 45 }, 46 Status: 42, 47 }, 48 } { 49 enc.Encode(ev) 50 } 51 eventf.Close() 52 53 err = readEventLog(s) 54 if err != nil { 55 t.Errorf("Failed to read event logs: %v", err) 56 } 57 58 if s.eventLog[0].Status != runtime.UnknownStatus { 59 t.Errorf("Improper event status: %v", s.eventLog[0].Status) 60 } 61 62 if s.eventLog[1].Status != 42 { 63 t.Errorf("Improper event status: %v", s.eventLog[1].Status) 64 } 65 }