mirror of https://github.com/perkeep/perkeep.git
camli/testing path cleanup.
Break lib/go/testing into lib/go/camli/test and lib/go/camli/test/asserts Moves TestBlob stuff and package 'testing' flags out of everybody's command flags. Also moves towards making the project filesystem match the import paths.
This commit is contained in:
parent
19a3910ec0
commit
386ad357b7
20
build.pl
20
build.pl
|
@ -284,23 +284,27 @@ TARGET: clients/go/camsync
|
|||
|
||||
TARGET: lib/go/schema
|
||||
- lib/go/blobref
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
|
||||
TARGET: lib/go/testing
|
||||
TARGET: lib/go/camli/test/asserts
|
||||
- lib/go/blobref
|
||||
|
||||
TARGET: lib/go/client
|
||||
- lib/go/blobref
|
||||
|
||||
TARGET: lib/go/jsonsign
|
||||
- lib/go/blobref
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
- lib/go/camli/test
|
||||
|
||||
TARGET: lib/go/camli/test
|
||||
|
||||
TARGET: lib/go/blobref
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
|
||||
TARGET: lib/go/blobserver
|
||||
- lib/go/blobref
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
|
||||
TARGET: lib/go/search
|
||||
- lib/go/blobref
|
||||
|
@ -311,12 +315,12 @@ TARGET: lib/go/blobserver/handlers
|
|||
- server/go/httputil
|
||||
- lib/go/blobserver
|
||||
- lib/go/httprange
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
|
||||
TARGET: lib/go/blobserver/localdisk
|
||||
- lib/go/blobref
|
||||
- lib/go/blobserver
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
|
||||
TARGET: lib/go/httprange
|
||||
|
||||
|
@ -328,5 +332,5 @@ TARGET: lib/go/mysqlindexer
|
|||
- lib/go/blobref
|
||||
- lib/go/blobserver
|
||||
- lib/go/schema
|
||||
- lib/go/testing
|
||||
- lib/go/camli/test/asserts
|
||||
- lib/go/search
|
||||
|
|
|
@ -4,6 +4,5 @@ TARG=camli/blobref
|
|||
GOFILES=\
|
||||
blobref.go\
|
||||
fetcher.go\
|
||||
testblob.go\
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
|
|
|
@ -18,7 +18,7 @@ package blobref
|
|||
|
||||
import (
|
||||
"testing"
|
||||
. "camli/testing"
|
||||
. "camli/test/asserts"
|
||||
)
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
|
|
|
@ -18,7 +18,7 @@ package blobserver
|
|||
|
||||
import (
|
||||
"camli/blobref"
|
||||
. "camli/testing"
|
||||
. "camli/test/asserts"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@ package handlers
|
|||
import (
|
||||
"camli/blobref"
|
||||
"camli/blobserver"
|
||||
. "camli/testing"
|
||||
. "camli/test/asserts"
|
||||
"http"
|
||||
"http/httptest"
|
||||
"os"
|
||||
|
|
|
@ -19,7 +19,7 @@ package localdisk
|
|||
import (
|
||||
"camli/blobref"
|
||||
"camli/blobserver"
|
||||
. "camli/testing"
|
||||
. "camli/test/asserts"
|
||||
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
|
|
@ -19,7 +19,7 @@ package localdisk
|
|||
import (
|
||||
"camli/blobref"
|
||||
"camli/blobserver"
|
||||
. "camli/testing"
|
||||
. "camli/test/asserts"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=camli/testing
|
||||
TARG=camli/test
|
||||
GOFILES=\
|
||||
testing.go\
|
||||
blob.go\
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
|
@ -0,0 +1,7 @@
|
|||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=camli/test/asserts
|
||||
GOFILES=\
|
||||
asserts.go\
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package testing
|
||||
package asserts
|
||||
|
||||
import (
|
||||
"os"
|
|
@ -14,39 +14,41 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
package blobref
|
||||
package test
|
||||
|
||||
import (
|
||||
"camli/blobref"
|
||||
|
||||
"crypto/sha1"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestBlob is a utility class for unit tests.
|
||||
type TestBlob struct {
|
||||
Val string
|
||||
// Blob is a utility class for unit tests.
|
||||
type Blob struct {
|
||||
Contents string // the contents of the blob
|
||||
}
|
||||
|
||||
func (tb *TestBlob) BlobRef() *BlobRef {
|
||||
func (tb *Blob) BlobRef() *blobref.BlobRef {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(tb.Val))
|
||||
return FromHash("sha1", h)
|
||||
h.Write([]byte(tb.Contents))
|
||||
return blobref.FromHash("sha1", h)
|
||||
}
|
||||
|
||||
func (tb *TestBlob) BlobRefSlice() []*BlobRef {
|
||||
return []*BlobRef{tb.BlobRef()}
|
||||
func (tb *Blob) BlobRefSlice() []*blobref.BlobRef {
|
||||
return []*blobref.BlobRef{tb.BlobRef()}
|
||||
}
|
||||
|
||||
func (tb *TestBlob) Size() int64 {
|
||||
return int64(len(tb.Val))
|
||||
func (tb *Blob) Size() int64 {
|
||||
return int64(len(tb.Contents))
|
||||
}
|
||||
|
||||
func (tb *TestBlob) Reader() io.Reader {
|
||||
return strings.NewReader(tb.Val)
|
||||
func (tb *Blob) Reader() io.Reader {
|
||||
return strings.NewReader(tb.Contents)
|
||||
}
|
||||
|
||||
func (tb *TestBlob) AssertMatches(t *testing.T, sb *SizedBlobRef) {
|
||||
func (tb *Blob) AssertMatches(t *testing.T, sb *blobref.SizedBlobRef) {
|
||||
if sb.Size != tb.Size() {
|
||||
t.Fatalf("Got size %d; expected %d", sb.Size, tb.Size())
|
||||
}
|
|
@ -18,7 +18,8 @@ package jsonsign
|
|||
|
||||
import (
|
||||
"camli/blobref"
|
||||
. "camli/testing"
|
||||
"camli/test"
|
||||
. "camli/test/asserts"
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -94,8 +95,8 @@ jyVNPb8AaaWVW1uZLg6Em61aKnbOG10B30m3CQ8dwBjF9hgmtcY0IZ/Y
|
|||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
`
|
||||
|
||||
var pubKeyBlob1 = &blobref.TestBlob{pubKey1} // user 1
|
||||
var pubKeyBlob2 = &blobref.TestBlob{pubKey2} // user 2
|
||||
var pubKeyBlob1 = &test.Blob{pubKey1} // user 1
|
||||
var pubKeyBlob2 = &test.Blob{pubKey2} // user 2
|
||||
|
||||
var testFetcher = &TestFetcher{}
|
||||
|
||||
|
@ -170,14 +171,14 @@ func TestSigning(t *testing.T) {
|
|||
|
||||
type TestFetcher struct {
|
||||
l sync.Mutex
|
||||
m map[string]*blobref.TestBlob
|
||||
m map[string]*test.Blob
|
||||
}
|
||||
|
||||
func (tf *TestFetcher) AddBlob(b *blobref.TestBlob) {
|
||||
func (tf *TestFetcher) AddBlob(b *test.Blob) {
|
||||
tf.l.Lock()
|
||||
defer tf.l.Unlock()
|
||||
if tf.m == nil {
|
||||
tf.m = make(map[string]*blobref.TestBlob)
|
||||
tf.m = make(map[string]*test.Blob)
|
||||
}
|
||||
tf.m[b.BlobRef().String()] = b
|
||||
}
|
||||
|
@ -194,8 +195,8 @@ func (tf *TestFetcher) Fetch(ref *blobref.BlobRef) (file blobref.ReadSeekCloser,
|
|||
err = os.ENOENT
|
||||
return
|
||||
}
|
||||
file = &strReader{tb.Val, 0}
|
||||
size = int64(len(tb.Val))
|
||||
file = &strReader{tb.Contents, 0}
|
||||
size = int64(len(tb.Contents))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
package schema
|
||||
|
||||
import (
|
||||
. "camli/testing"
|
||||
. "camli/test/asserts"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
Loading…
Reference in New Issue