log_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package eventlog_test
  6. import (
  7. "testing"
  8. "golang.org/x/sys/windows/svc/eventlog"
  9. )
  10. func TestLog(t *testing.T) {
  11. if testing.Short() {
  12. t.Skip("skipping test in short mode - it modifies system logs")
  13. }
  14. const name = "mylog"
  15. const supports = eventlog.Error | eventlog.Warning | eventlog.Info
  16. err := eventlog.InstallAsEventCreate(name, supports)
  17. if err != nil {
  18. t.Fatalf("Install failed: %s", err)
  19. }
  20. defer func() {
  21. err = eventlog.Remove(name)
  22. if err != nil {
  23. t.Fatalf("Remove failed: %s", err)
  24. }
  25. }()
  26. l, err := eventlog.Open(name)
  27. if err != nil {
  28. t.Fatalf("Open failed: %s", err)
  29. }
  30. defer l.Close()
  31. err = l.Info(1, "info")
  32. if err != nil {
  33. t.Fatalf("Info failed: %s", err)
  34. }
  35. err = l.Warning(2, "warning")
  36. if err != nil {
  37. t.Fatalf("Warning failed: %s", err)
  38. }
  39. err = l.Error(3, "error")
  40. if err != nil {
  41. t.Fatalf("Error failed: %s", err)
  42. }
  43. }