Skip to content

Commit

Permalink
[FAB-4113] Remove some skipped unit tests.
Browse files Browse the repository at this point in the history
In order to test error handling of filesystem read/write, these tests
chmod file/dir to emulate filesystem error. However, this does not work
in the CI, because tests are run as 'root' in the container, which does
not respect access permission.

Change-Id: I4954153e52f29daa227a5b6b655a5ab6c7abd473
Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
  • Loading branch information
guoger committed Aug 1, 2017
1 parent d788450 commit 7227351
Showing 1 changed file with 1 addition and 51 deletions.
52 changes: 1 addition & 51 deletions orderer/common/ledger/json/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ limitations under the License.
package jsonledger

import (
"testing"

"fmt"
"io/ioutil"
"os"
"path"
"testing"

"github.com/hyperledger/fabric/common/configtx/tool/provisional"
logging "github.com/op/go-logging"
"github.com/stretchr/testify/assert"
)
Expand All @@ -33,10 +31,6 @@ func init() {
logging.SetLevel(logging.DEBUG, "")
}

// Some tests are skipped because `os.Chmod` does not take effect in the CI. The call
// itself does not fail, but file mod is not changed, which cause tests to fail.
// TODO(jay_guo): re-enable skipped tests once we sort out this problem.

// This test checks that `New` factory should fail if parent directory is read-only
func TestErrorMkdir(t *testing.T) {
name, err := ioutil.TempDir("", "hyperledger_fabric")
Expand All @@ -48,19 +42,6 @@ func TestErrorMkdir(t *testing.T) {
assert.Panics(t, func() { New(ledgerPath) }, "Should have failed to create factory")
}

// This test checks that `New` factory should fail if factory directory is not readable
func TestErrorReadDir(t *testing.T) {
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")

name, err := ioutil.TempDir("", "hyperledger_fabric")
assert.Nil(t, err, "Error creating temp dir: %s", err)
defer os.RemoveAll(name)
assert.Nil(t, os.Chmod(name, 0200), "Error chmod temp dir")
defer os.Chmod(name, 0700)

assert.Panics(t, func() { New(name) }, "Should have failed to create factory")
}

// This test checks that factory initialization should ignore dir with invalid name and files.
// NOTE: unfortunately this test does not really test intended logic because errors caused by
// constructing a chain from invalid dir or file are ignored anyway. Consider refactoring impl
Expand Down Expand Up @@ -88,14 +69,6 @@ func TestInvalidChain(t *testing.T) {
chainDir, err := ioutil.TempDir(name, "chain_")
assert.Nil(t, err, "Error creating temp dir: %s", err)

t.Run("ChainDirNotReadable", func(t *testing.T) {
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")
assert.Nil(t, os.Chmod(chainDir, 0200), "Error chmod chain dir")
defer os.Chmod(chainDir, 0700)
assert.Panics(t, func() { New(name) }, "Expected initialization panics if chain dir is not readable")
assert.Nil(t, os.Chmod(chainDir, 0700), "Error chmod chain dir")
})

// Skip Block 0 to trigger MissingBlock error
secondBlock := path.Join(chainDir, fmt.Sprintf(blockFileFormatString, 1))
assert.NoError(t, ioutil.WriteFile(secondBlock, nil, 0700))
Expand All @@ -114,14 +87,6 @@ func TestInvalidChain(t *testing.T) {
firstBlock := path.Join(chainDir, fmt.Sprintf(blockFileFormatString, 0))
assert.NoError(t, ioutil.WriteFile(firstBlock, nil, 0700))

t.Run("BlockNotReadable", func(t *testing.T) {
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")
assert.NoError(t, os.Chmod(secondBlock, 0200))
defer os.Chmod(secondBlock, 0700)
assert.Panics(t, func() { New(name) }, "Expected initialization panics if block is not readable")
assert.NoError(t, os.Chmod(secondBlock, 0700))
})

t.Run("MalformedBlock", func(t *testing.T) {
assert.Panics(t, func() { New(name) }, "Expected initialization panics if block is malformed")
})
Expand All @@ -146,21 +111,6 @@ func TestIgnoreInvalidBlockFileName(t *testing.T) {
assert.Zero(t, chain.Height(), "Expected chain to be empty")
}

// This test checks that fs error causes creating chain to fail
func TestErrorCreatingChain(t *testing.T) {
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")

name, err := ioutil.TempDir("", "hyperledger_fabric")
assert.Nil(t, err, "Error creating temp dir: %s", err)
defer os.RemoveAll(name)

jlf := New(name)
assert.NoError(t, os.Chmod(name, 0400))
defer os.Chmod(name, 0700)
_, err = jlf.GetOrCreate(provisional.TestChainID)
assert.Error(t, err, "Should have failed to create chain due to fs error")
}

func TestClose(t *testing.T) {
name, err := ioutil.TempDir("", "hyperledger_fabric")
assert.Nil(t, err, "Error creating temp dir: %s", err)
Expand Down

0 comments on commit 7227351

Please sign in to comment.