| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. | 1 // Copyright 2015 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package archiver | 15 package archiver |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "encoding/json" | 18 "encoding/json" |
| 19 "errors" | |
| 20 "io/ioutil" | 19 "io/ioutil" |
| 21 "net/http/httptest" | 20 "net/http/httptest" |
| 22 "os" | 21 "os" |
| 23 "path/filepath" | 22 "path/filepath" |
| 24 "sync" | |
| 25 "testing" | 23 "testing" |
| 26 | 24 |
| 27 "golang.org/x/net/context" | 25 "golang.org/x/net/context" |
| 28 | 26 |
| 29 "github.com/luci/luci-go/client/internal/common" | 27 "github.com/luci/luci-go/client/internal/common" |
| 30 "github.com/luci/luci-go/common/data/text/units" | 28 "github.com/luci/luci-go/common/data/text/units" |
| 31 "github.com/luci/luci-go/common/isolated" | 29 "github.com/luci/luci-go/common/isolated" |
| 32 "github.com/luci/luci-go/common/isolatedclient" | 30 "github.com/luci/luci-go/common/isolatedclient" |
| 33 "github.com/luci/luci-go/common/isolatedclient/isolatedfake" | 31 "github.com/luci/luci-go/common/isolatedclient/isolatedfake" |
| 34 | 32 |
| 35 . "github.com/smartystreets/goconvey/convey" | 33 . "github.com/smartystreets/goconvey/convey" |
| 36 ) | 34 ) |
| 37 | 35 |
| 38 func TestWalkBadRegexp(t *testing.T) { | |
| 39 Convey(`A bad regexp should fail when walking a directory.`, t, func() { | |
| 40 ch := make(chan *walkItem) | |
| 41 var wg sync.WaitGroup | |
| 42 wg.Add(1) | |
| 43 go func() { | |
| 44 defer wg.Done() | |
| 45 defer close(ch) | |
| 46 walk("inexistent", []string{"a["}, ch) | |
| 47 }() | |
| 48 item := <-ch | |
| 49 So(item, ShouldResemble, &walkItem{err: errors.New("bad blacklis
t pattern \"a[\"")}) | |
| 50 item, ok := <-ch | |
| 51 So(item, ShouldBeNil) | |
| 52 So(ok, ShouldBeFalse) | |
| 53 wg.Wait() | |
| 54 }) | |
| 55 } | |
| 56 | |
| 57 func TestPushDirectory(t *testing.T) { | 36 func TestPushDirectory(t *testing.T) { |
| 58 // Uploads a real directory. 2 times the same file. | 37 // Uploads a real directory. 2 times the same file. |
| 59 t.Parallel() | 38 t.Parallel() |
| 60 emptyContext := context.Background() | 39 emptyContext := context.Background() |
| 61 | 40 |
| 62 Convey(`Pushing a real directory should upload the directory.`, t, func(
) { | 41 Convey(`Pushing a real directory should upload the directory.`, t, func(
) { |
| 63 server := isolatedfake.New() | 42 server := isolatedfake.New() |
| 64 ts := httptest.NewServer(server) | 43 ts := httptest.NewServer(server) |
| 65 defer ts.Close() | 44 defer ts.Close() |
| 66 a := New(emptyContext, isolatedclient.New(nil, nil, ts.URL, isol
atedclient.DefaultNamespace, nil, nil), nil) | 45 a := New(emptyContext, isolatedclient.New(nil, nil, ts.URL, isol
atedclient.DefaultNamespace, nil, nil), nil) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 stats := a.Stats() | 103 stats := a.Stats() |
| 125 So(stats.TotalHits(), ShouldResemble, 0) | 104 So(stats.TotalHits(), ShouldResemble, 0) |
| 126 // There're 3 cache misses even if the same content is looked up
twice. | 105 // There're 3 cache misses even if the same content is looked up
twice. |
| 127 So(stats.TotalMisses(), ShouldResemble, 3) | 106 So(stats.TotalMisses(), ShouldResemble, 3) |
| 128 So(stats.TotalBytesHits(), ShouldResemble, units.Size(0)) | 107 So(stats.TotalBytesHits(), ShouldResemble, units.Size(0)) |
| 129 So(stats.TotalBytesPushed(), ShouldResemble, units.Size(3+3+len(
isolatedEncoded))) | 108 So(stats.TotalBytesPushed(), ShouldResemble, units.Size(3+3+len(
isolatedEncoded))) |
| 130 | 109 |
| 131 So(server.Error(), ShouldBeNil) | 110 So(server.Error(), ShouldBeNil) |
| 132 }) | 111 }) |
| 133 } | 112 } |
| OLD | NEW |