2011-03-19 08:11:15 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
nYou may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package magic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
2011-12-03 21:37:07 +00:00
|
|
|
|
2012-03-20 01:44:50 +00:00
|
|
|
. "camlistore.org/pkg/test/asserts"
|
2011-03-19 08:11:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type magicTest struct {
|
2011-12-03 21:37:07 +00:00
|
|
|
fileName, data string // one of these set
|
|
|
|
want string
|
2011-03-19 08:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var tests = []magicTest{
|
2011-12-03 21:37:07 +00:00
|
|
|
{fileName: "smile.jpg", want: "image/jpeg"},
|
|
|
|
{fileName: "smile.png", want: "image/png"},
|
|
|
|
{data: "<html>foo</html>", want: "text/html"},
|
|
|
|
{data: "\xff", want: ""},
|
2011-03-19 08:11:15 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 21:37:07 +00:00
|
|
|
func TestMagic(t *testing.T) {
|
|
|
|
for i, tt := range tests {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
var err error
|
2011-12-03 21:37:07 +00:00
|
|
|
data := []byte(tt.data)
|
|
|
|
if tt.fileName != "" {
|
|
|
|
data, err = ioutil.ReadFile("testdata/" + tt.fileName)
|
|
|
|
AssertNil(t, err, "no error reading "+tt.fileName)
|
|
|
|
}
|
2013-07-08 04:12:18 +00:00
|
|
|
mime := MIMEType(data)
|
2011-12-03 21:37:07 +00:00
|
|
|
if mime != tt.want {
|
|
|
|
t.Errorf("%d. got %q; want %q", i, mime, tt.want)
|
|
|
|
}
|
2011-03-19 08:11:15 +00:00
|
|
|
}
|
|
|
|
}
|