| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package archiver | 5 package archiver |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "errors" | 9 "errors" |
| 10 "fmt" | |
| 11 "io/ioutil" | 10 "io/ioutil" |
| 12 "net/http/httptest" | 11 "net/http/httptest" |
| 13 "os" | 12 "os" |
| 14 "path/filepath" | 13 "path/filepath" |
| 15 "sync" | 14 "sync" |
| 16 "testing" | 15 "testing" |
| 17 | 16 |
| 18 "github.com/luci/luci-go/client/internal/common" | 17 "github.com/luci/luci-go/client/internal/common" |
| 19 "github.com/luci/luci-go/common/data/text/units" | 18 "github.com/luci/luci-go/common/data/text/units" |
| 20 "github.com/luci/luci-go/common/isolated" | 19 "github.com/luci/luci-go/common/isolated" |
| 21 "github.com/luci/luci-go/common/isolatedclient" | 20 "github.com/luci/luci-go/common/isolatedclient" |
| 22 "github.com/luci/luci-go/common/isolatedclient/isolatedfake" | 21 "github.com/luci/luci-go/common/isolatedclient/isolatedfake" |
| 23 "github.com/maruel/ut" | 22 "github.com/maruel/ut" |
| 24 ) | 23 ) |
| 25 | 24 |
| 26 func TestWalkInexistent(t *testing.T) { | |
| 27 ch := make(chan *walkItem) | |
| 28 var wg sync.WaitGroup | |
| 29 wg.Add(1) | |
| 30 go func() { | |
| 31 defer wg.Done() | |
| 32 defer close(ch) | |
| 33 walk("inexistent_directory", nil, ch) | |
| 34 }() | |
| 35 item := <-ch | |
| 36 osErr := "lstat inexistent_directory: no such file or directory" | |
| 37 if common.IsWindows() { | |
| 38 osErr = "GetFileAttributesEx inexistent_directory: The system ca
nnot find the file specified." | |
| 39 } | |
| 40 err := fmt.Errorf("walk(inexistent_directory): %s", osErr) | |
| 41 ut.AssertEqual(t, &walkItem{err: err}, item) | |
| 42 item, ok := <-ch | |
| 43 ut.AssertEqual(t, (*walkItem)(nil), item) | |
| 44 ut.AssertEqual(t, false, ok) | |
| 45 wg.Wait() | |
| 46 } | |
| 47 | |
| 48 func TestWalkBadRegexp(t *testing.T) { | 25 func TestWalkBadRegexp(t *testing.T) { |
| 49 ch := make(chan *walkItem) | 26 ch := make(chan *walkItem) |
| 50 var wg sync.WaitGroup | 27 var wg sync.WaitGroup |
| 51 wg.Add(1) | 28 wg.Add(1) |
| 52 go func() { | 29 go func() { |
| 53 defer wg.Done() | 30 defer wg.Done() |
| 54 defer close(ch) | 31 defer close(ch) |
| 55 walk("inexistent", []string{"a["}, ch) | 32 walk("inexistent", []string{"a["}, ch) |
| 56 }() | 33 }() |
| 57 item := <-ch | 34 item := <-ch |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 105 |
| 129 stats := a.Stats() | 106 stats := a.Stats() |
| 130 ut.AssertEqual(t, 0, stats.TotalHits()) | 107 ut.AssertEqual(t, 0, stats.TotalHits()) |
| 131 // There're 3 cache misses even if the same content is looked up twice. | 108 // There're 3 cache misses even if the same content is looked up twice. |
| 132 ut.AssertEqual(t, 3, stats.TotalMisses()) | 109 ut.AssertEqual(t, 3, stats.TotalMisses()) |
| 133 ut.AssertEqual(t, units.Size(0), stats.TotalBytesHits()) | 110 ut.AssertEqual(t, units.Size(0), stats.TotalBytesHits()) |
| 134 ut.AssertEqual(t, units.Size(3+3+len(isolatedEncoded)), stats.TotalBytes
Pushed()) | 111 ut.AssertEqual(t, units.Size(3+3+len(isolatedEncoded)), stats.TotalBytes
Pushed()) |
| 135 | 112 |
| 136 ut.AssertEqual(t, nil, server.Error()) | 113 ut.AssertEqual(t, nil, server.Error()) |
| 137 } | 114 } |
| OLD | NEW |