logging_storage_test.go 932 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package logging
  2. import (
  3. "context"
  4. "strings"
  5. "testing"
  6. "github.com/kopia/kopia/internal/blobtesting"
  7. )
  8. func TestLoggingStorage(t *testing.T) {
  9. var outputCount int
  10. myPrefix := "myprefix"
  11. myOutput := func(msg string, args ...interface{}) {
  12. if !strings.HasPrefix(msg, myPrefix) {
  13. t.Errorf("unexpected prefix %v", msg)
  14. }
  15. outputCount++
  16. }
  17. data := blobtesting.DataMap{}
  18. underlying := blobtesting.NewMapStorage(data, nil, nil)
  19. st := NewWrapper(underlying, Output(myOutput), Prefix(myPrefix))
  20. if st == nil {
  21. t.Fatalf("unexpected result: %v", st)
  22. }
  23. ctx := context.Background()
  24. blobtesting.VerifyStorage(ctx, t, st)
  25. if err := st.Close(ctx); err != nil {
  26. t.Fatalf("err: %v", err)
  27. }
  28. if outputCount == 0 {
  29. t.Errorf("did not write any output!")
  30. }
  31. if got, want := st.ConnectionInfo().Type, underlying.ConnectionInfo().Type; got != want {
  32. t.Errorf("unexpected connection infor %v, want %v", got, want)
  33. }
  34. }