Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1267)

Unified Diff: go/src/infra/tools/cipd/local/testing.go

Issue 1129043003: cipd: Refactor client to make it more readable. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/tools/cipd/local/reader_test.go ('k') | go/src/infra/tools/cipd/pkgdef.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/tools/cipd/local/testing.go
diff --git a/go/src/infra/tools/cipd/local/testing.go b/go/src/infra/tools/cipd/local/testing.go
new file mode 100644
index 0000000000000000000000000000000000000000..58a53f86a0904c07c298bd0d85299e97006bbf93
--- /dev/null
+++ b/go/src/infra/tools/cipd/local/testing.go
@@ -0,0 +1,58 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package local
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "io/ioutil"
+)
+
+// NewTestFile returns File implementation (Symlink == false) backed by a fake
+// in-memory data. It is useful in unit tests.
+func NewTestFile(name string, data string, executable bool) File {
+ return &testFile{
+ name: name,
+ data: data,
+ executable: executable,
+ }
+}
+
+// NewTestSymlink returns File implementation (Symlink == true) backed by a fake
+// in-memory data. It is useful in unit tests.
+func NewTestSymlink(name string, target string) File {
+ return &testFile{
+ name: name,
+ symlinkTarget: target,
+ }
+}
+
+type testFile struct {
+ name string
+ data string
+ executable bool
+ symlinkTarget string
+}
+
+func (f *testFile) Name() string { return f.name }
+func (f *testFile) Size() uint64 { return uint64(len(f.data)) }
+func (f *testFile) Executable() bool { return f.executable }
+func (f *testFile) Symlink() bool { return f.symlinkTarget != "" }
+
+func (f *testFile) SymlinkTarget() (string, error) {
+ if f.symlinkTarget == "" {
+ return "", fmt.Errorf("Not a symlink: %s", f.Name())
+ }
+ return f.symlinkTarget, nil
+}
+
+func (f *testFile) Open() (io.ReadCloser, error) {
+ if f.Symlink() {
+ return nil, fmt.Errorf("Can't open symlink: %s", f.Name())
+ }
+ r := bytes.NewReader([]byte(f.data))
+ return ioutil.NopCloser(r), nil
+}
« no previous file with comments | « go/src/infra/tools/cipd/local/reader_test.go ('k') | go/src/infra/tools/cipd/pkgdef.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698