mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
Further fixes -
- All test files have been renamed to their respective <package>_test name,
this is done in accordance with
- https://github.com/golang/go/wiki/CodeReviewComments#import-dot
imports are largely used in testing, but to avoid namespace collision
and circular dependencies
- Never use _* in package names other than "_test" change fragment_v1 to expose
fragment just like 'gopkg.in/check.v1'
This commit is contained in:
@@ -25,7 +25,7 @@ var castanagoliTable = crc32.MakeTable(crc32.Castagnoli)
|
||||
|
||||
/// Convenience functions
|
||||
|
||||
// Single caller crc helper
|
||||
// Sum32 - single caller crc helper
|
||||
func Sum32(buffer []byte) uint32 {
|
||||
crc := crc32.New(castanagoliTable)
|
||||
crc.Reset()
|
||||
@@ -33,7 +33,7 @@ func Sum32(buffer []byte) uint32 {
|
||||
return crc.Sum32()
|
||||
}
|
||||
|
||||
// Low memory footprint io.Reader based crc helper
|
||||
// Sum - io.Reader based crc helper
|
||||
func Sum(reader io.Reader) (uint32, error) {
|
||||
h := New()
|
||||
var err error
|
||||
|
||||
@@ -27,9 +27,9 @@ import (
|
||||
|
||||
// Config context
|
||||
type Config struct {
|
||||
configPath string
|
||||
configFile string
|
||||
configLock *sync.RWMutex
|
||||
ConfigPath string
|
||||
ConfigFile string
|
||||
ConfigLock *sync.RWMutex
|
||||
Users map[string]User
|
||||
}
|
||||
|
||||
@@ -52,22 +52,22 @@ func (c *Config) SetupConfig() error {
|
||||
return err
|
||||
}
|
||||
|
||||
c.configPath = confPath
|
||||
c.configFile = path.Join(c.configPath, "config.json")
|
||||
if _, err := os.Stat(c.configFile); os.IsNotExist(err) {
|
||||
_, err = os.Create(c.configFile)
|
||||
c.ConfigPath = confPath
|
||||
c.ConfigFile = path.Join(c.ConfigPath, "config.json")
|
||||
if _, err := os.Stat(c.ConfigFile); os.IsNotExist(err) {
|
||||
_, err = os.Create(c.ConfigFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c.configLock = new(sync.RWMutex)
|
||||
c.ConfigLock = new(sync.RWMutex)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConfigPath config file location
|
||||
func (c *Config) GetConfigPath() string {
|
||||
return c.configPath
|
||||
return c.ConfigPath
|
||||
}
|
||||
|
||||
// IsUserExists verify if user exists
|
||||
@@ -104,13 +104,13 @@ func (c *Config) AddUser(user User) {
|
||||
|
||||
// WriteConfig - write encoded json in config file
|
||||
func (c *Config) WriteConfig() error {
|
||||
c.configLock.Lock()
|
||||
defer c.configLock.Unlock()
|
||||
c.ConfigLock.Lock()
|
||||
defer c.ConfigLock.Unlock()
|
||||
|
||||
var file *os.File
|
||||
var err error
|
||||
|
||||
file, err = os.OpenFile(c.configFile, os.O_WRONLY, 0666)
|
||||
file, err = os.OpenFile(c.ConfigFile, os.O_WRONLY, 0666)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -123,13 +123,13 @@ func (c *Config) WriteConfig() error {
|
||||
|
||||
// ReadConfig - read json config file and decode
|
||||
func (c *Config) ReadConfig() error {
|
||||
c.configLock.RLock()
|
||||
defer c.configLock.RUnlock()
|
||||
c.ConfigLock.RLock()
|
||||
defer c.ConfigLock.RUnlock()
|
||||
|
||||
var file *os.File
|
||||
var err error
|
||||
|
||||
file, err = os.OpenFile(c.configFile, os.O_RDONLY, 0666)
|
||||
file, err = os.OpenFile(c.ConfigFile, os.O_RDONLY, 0666)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/config"
|
||||
"github.com/minio-io/minio/pkg/utils/crypto/keys"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
@@ -34,22 +35,22 @@ var _ = Suite(&MySuite{})
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
func (s *MySuite) TestConfig(c *C) {
|
||||
conf := Config{}
|
||||
conf.configPath, _ = ioutil.TempDir("/tmp", "minio-test-")
|
||||
defer os.RemoveAll(conf.configPath)
|
||||
conf.configFile = path.Join(conf.configPath, "config.json")
|
||||
if _, err := os.Stat(conf.configFile); os.IsNotExist(err) {
|
||||
_, err = os.Create(conf.configFile)
|
||||
conf := config.Config{}
|
||||
conf.ConfigPath, _ = ioutil.TempDir("/tmp", "minio-test-")
|
||||
defer os.RemoveAll(conf.ConfigPath)
|
||||
conf.ConfigFile = path.Join(conf.ConfigPath, "config.json")
|
||||
if _, err := os.Stat(conf.ConfigFile); os.IsNotExist(err) {
|
||||
_, err = os.Create(conf.ConfigFile)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
}
|
||||
conf.configLock = new(sync.RWMutex)
|
||||
conf.ConfigLock = new(sync.RWMutex)
|
||||
|
||||
accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
|
||||
secretkey, _ := keys.GenerateRandomBase64(keys.MinioSecretID)
|
||||
|
||||
user := User{
|
||||
user := config.User{
|
||||
Name: "gnubot",
|
||||
AccessKey: string(accesskey),
|
||||
SecretKey: string(secretkey),
|
||||
@@ -64,7 +65,7 @@ func (s *MySuite) TestConfig(c *C) {
|
||||
|
||||
accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
|
||||
secretkey, _ = keys.GenerateRandomBase64(keys.MinioSecretID)
|
||||
user = User{
|
||||
user = config.User{
|
||||
Name: "minio",
|
||||
AccessKey: string(accesskey),
|
||||
SecretKey: string(secretkey),
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package cpu
|
||||
package cpu_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/cpu"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -49,7 +50,7 @@ func hasCPUFeatureFromOS(feature string) (bool, error) {
|
||||
|
||||
func (s *MySuite) TestHasSSE41(c *C) {
|
||||
if runtime.GOOS == "linux" {
|
||||
var flag = HasSSE41()
|
||||
var flag = cpu.HasSSE41()
|
||||
osCheck, err := hasCPUFeatureFromOS("sse4_1")
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(flag, Equals, osCheck)
|
||||
@@ -58,7 +59,7 @@ func (s *MySuite) TestHasSSE41(c *C) {
|
||||
|
||||
func (s *MySuite) TestHasAVX(c *C) {
|
||||
if runtime.GOOS == "linux" {
|
||||
var flag = HasAVX()
|
||||
var flag = cpu.HasAVX()
|
||||
osFlag, err := hasCPUFeatureFromOS("avx")
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(osFlag, Equals, flag)
|
||||
@@ -67,7 +68,7 @@ func (s *MySuite) TestHasAVX(c *C) {
|
||||
|
||||
func (s *MySuite) TestHasAVX2(c *C) {
|
||||
if runtime.GOOS == "linux" {
|
||||
var flag = HasAVX2()
|
||||
var flag = cpu.HasAVX2()
|
||||
osFlag, err := hasCPUFeatureFromOS("avx2")
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(osFlag, Equals, flag)
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package keys
|
||||
package keys_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/crypto/keys"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -28,11 +29,11 @@ type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) Testing(c *C) {
|
||||
value, err := GenerateRandomBase64(MinioSecretID)
|
||||
func (s *MySuite) TestingKeys(c *C) {
|
||||
value, err := keys.GenerateRandomBase64(keys.MinioSecretID)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
alphanum, err := GenerateRandomAlphaNumeric(MinioAccessID)
|
||||
alphanum, err := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Log(string(value))
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package md5
|
||||
package md5_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/crypto/md5"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,7 @@ var _ = Suite(&MySuite{})
|
||||
func (s *MySuite) TestMd5sum(c *C) {
|
||||
testString := []byte("Test string")
|
||||
expectedHash, _ := hex.DecodeString("0fd3dbec9730101bff92acc820befc34")
|
||||
hash, err := Sum(bytes.NewBuffer(testString))
|
||||
hash, err := md5.Sum(bytes.NewBuffer(testString))
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(bytes.Equal(expectedHash, hash), Equals, true)
|
||||
}
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package x509
|
||||
package x509_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/crypto/x509"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -30,8 +31,8 @@ type MySuite struct{}
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) Testing(c *C) {
|
||||
certObj := Certificates{}
|
||||
params := Params{
|
||||
certObj := x509.Certificates{}
|
||||
params := x509.Params{
|
||||
Hostname: "example.com",
|
||||
IsCA: false,
|
||||
EcdsaCurve: "P224",
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package split
|
||||
package split_test
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/minio-io/minio/pkg/utils/split"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -41,7 +42,7 @@ func (s *MySuite) TestSplitStream(c *C) {
|
||||
}
|
||||
bytesWriter.Flush()
|
||||
reader := bytes.NewReader(bytesBuffer.Bytes())
|
||||
ch := Stream(reader, 25)
|
||||
ch := split.Stream(reader, 25)
|
||||
var resultsBuffer bytes.Buffer
|
||||
resultsWriter := bufio.NewWriter(&resultsBuffer)
|
||||
for chunk := range ch {
|
||||
@@ -52,17 +53,17 @@ func (s *MySuite) TestSplitStream(c *C) {
|
||||
}
|
||||
|
||||
func (s *MySuite) TestFileSplitJoin(c *C) {
|
||||
err := FileWithPrefix("test-data/TESTFILE", 1024, "TESTPREFIX")
|
||||
err := split.FileWithPrefix("test-data/TESTFILE", 1024, "TESTPREFIX")
|
||||
c.Assert(err, IsNil)
|
||||
err = FileWithPrefix("test-data/TESTFILE", 1024, "")
|
||||
err = split.FileWithPrefix("test-data/TESTFILE", 1024, "")
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
devnull, err := os.OpenFile(os.DevNull, 2, os.ModeAppend)
|
||||
defer devnull.Close()
|
||||
reader := JoinFiles(".", "ERROR")
|
||||
reader := split.JoinFiles(".", "ERROR")
|
||||
_, err = io.Copy(devnull, reader)
|
||||
c.Assert(err, Not(IsNil))
|
||||
reader = JoinFiles(".", "TESTPREFIX")
|
||||
reader = split.JoinFiles(".", "TESTPREFIX")
|
||||
_, err = io.Copy(devnull, reader)
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user