Add a global fix for anything that involves GetHashPrefixAndSuffix
We tackled this previously with commit 6f78542637b80671cf3153dad8e15ce54dedbb39, but that fix did not go far enough. Other modules invoke ./hummingbird, so their tests need the same faking that makeReplicator() needs. Note that we have 2 kinds of tests: the one that tests the GetHashPrefixAndSuffix itself and the rest, which uses the GetHashPrefixAndSuffix in the process of testing something else. We create a test file for the former and fake everything without any files for the latter. Change-Id: Id87cfa6f5271111ae194316de170c6707ba6f23c
This commit is contained in:
parent
a331f77253
commit
ffe0901240
@ -489,7 +489,11 @@ var configLocations = []string{"/etc/hummingbird/hummingbird.conf", "/etc/swift/
|
||||
// GetHashPrefixAndSuffix retrieves the hash path prefix and suffix from
|
||||
// the correct configs based on the environments setup. The suffix cannot
|
||||
// be nil
|
||||
func GetHashPrefixAndSuffix() (prefix string, suffix string, err error) {
|
||||
type getHashPrefixAndSuffixFunc func() (pfx string, sfx string, err error)
|
||||
|
||||
var GetHashPrefixAndSuffix getHashPrefixAndSuffixFunc = normalGetHashPrefixAndSuffix
|
||||
|
||||
func normalGetHashPrefixAndSuffix() (prefix string, suffix string, err error) {
|
||||
for _, loc := range configLocations {
|
||||
if conf, e := LoadConfig(loc); e == nil {
|
||||
var ok bool
|
||||
|
@ -273,14 +273,24 @@ func TestReadDirNames(t *testing.T) {
|
||||
assert.Equal(t, fileNames, []string{"X", "Y", "Z"})
|
||||
}
|
||||
|
||||
func TestGetHashPrefixAndSuffix(t *testing.T) {
|
||||
func fakeHashPrefixAndSuffix() (filename string, err error) {
|
||||
var config_source []byte = []byte(
|
||||
"[swift-hash]\n" +
|
||||
"swift_hash_path_suffix = 983abc1de3ff4258\n")
|
||||
tempFile, _ := ioutil.TempFile("", "swift.conf-")
|
||||
defer os.RemoveAll(tempFile.Name())
|
||||
tempFile, err := ioutil.TempFile("", "swift.conf-")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ioutil.WriteFile(tempFile.Name(), config_source, 0600)
|
||||
configLocations = []string{tempFile.Name()}
|
||||
return tempFile.Name(), nil
|
||||
}
|
||||
|
||||
func TestGetHashPrefixAndSuffix(t *testing.T) {
|
||||
swift_conf_name, err := fakeHashPrefixAndSuffix()
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(swift_conf_name)
|
||||
|
||||
_, suffix, err := GetHashPrefixAndSuffix()
|
||||
assert.Nil(t, err, "Error getting hash path prefix or suffix")
|
||||
|
||||
|
18
go/objectserver/_test.go
Normal file
18
go/objectserver/_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2016 Red Hat, Inc.
|
||||
|
||||
package objectserver
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/openstack/swift/go/hummingbird"
|
||||
)
|
||||
|
||||
func testGetHashPrefixAndSuffix() (pfx string, sfx string, err error) {
|
||||
return "", "983abc1de3ff4258", nil
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
hummingbird.GetHashPrefixAndSuffix = testGetHashPrefixAndSuffix
|
||||
os.Exit(m.Run())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user