mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user