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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package local
6
7 import (
8 "bytes"
9 "fmt"
10 "io"
11 "io/ioutil"
12 )
13
14 // NewTestFile returns File implementation (Symlink == false) backed by a fake
15 // in-memory data. It is useful in unit tests.
16 func NewTestFile(name string, data string, executable bool) File {
17 return &testFile{
18 name: name,
19 data: data,
20 executable: executable,
21 }
22 }
23
24 // NewTestSymlink returns File implementation (Symlink == true) backed by a fake
25 // in-memory data. It is useful in unit tests.
26 func NewTestSymlink(name string, target string) File {
27 return &testFile{
28 name: name,
29 symlinkTarget: target,
30 }
31 }
32
33 type testFile struct {
34 name string
35 data string
36 executable bool
37 symlinkTarget string
38 }
39
40 func (f *testFile) Name() string { return f.name }
41 func (f *testFile) Size() uint64 { return uint64(len(f.data)) }
42 func (f *testFile) Executable() bool { return f.executable }
43 func (f *testFile) Symlink() bool { return f.symlinkTarget != "" }
44
45 func (f *testFile) SymlinkTarget() (string, error) {
46 if f.symlinkTarget == "" {
47 return "", fmt.Errorf("Not a symlink: %s", f.Name())
48 }
49 return f.symlinkTarget, nil
50 }
51
52 func (f *testFile) Open() (io.ReadCloser, error) {
53 if f.Symlink() {
54 return nil, fmt.Errorf("Can't open symlink: %s", f.Name())
55 }
56 r := bytes.NewReader([]byte(f.data))
57 return ioutil.NopCloser(r), nil
58 }
OLDNEW
« 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