Skip to content

Commit 7227351

Browse files
committed
[FAB-4113] Remove some skipped unit tests.
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>
1 parent d788450 commit 7227351

File tree

1 file changed

+1
-51
lines changed

1 file changed

+1
-51
lines changed

orderer/common/ledger/json/factory_test.go

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ limitations under the License.
1717
package jsonledger
1818

1919
import (
20-
"testing"
21-
2220
"fmt"
2321
"io/ioutil"
2422
"os"
2523
"path"
24+
"testing"
2625

27-
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
2826
logging "github.com/op/go-logging"
2927
"github.com/stretchr/testify/assert"
3028
)
@@ -33,10 +31,6 @@ func init() {
3331
logging.SetLevel(logging.DEBUG, "")
3432
}
3533

36-
// Some tests are skipped because `os.Chmod` does not take effect in the CI. The call
37-
// itself does not fail, but file mod is not changed, which cause tests to fail.
38-
// TODO(jay_guo): re-enable skipped tests once we sort out this problem.
39-
4034
// This test checks that `New` factory should fail if parent directory is read-only
4135
func TestErrorMkdir(t *testing.T) {
4236
name, err := ioutil.TempDir("", "hyperledger_fabric")
@@ -48,19 +42,6 @@ func TestErrorMkdir(t *testing.T) {
4842
assert.Panics(t, func() { New(ledgerPath) }, "Should have failed to create factory")
4943
}
5044

51-
// This test checks that `New` factory should fail if factory directory is not readable
52-
func TestErrorReadDir(t *testing.T) {
53-
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")
54-
55-
name, err := ioutil.TempDir("", "hyperledger_fabric")
56-
assert.Nil(t, err, "Error creating temp dir: %s", err)
57-
defer os.RemoveAll(name)
58-
assert.Nil(t, os.Chmod(name, 0200), "Error chmod temp dir")
59-
defer os.Chmod(name, 0700)
60-
61-
assert.Panics(t, func() { New(name) }, "Should have failed to create factory")
62-
}
63-
6445
// This test checks that factory initialization should ignore dir with invalid name and files.
6546
// NOTE: unfortunately this test does not really test intended logic because errors caused by
6647
// constructing a chain from invalid dir or file are ignored anyway. Consider refactoring impl
@@ -88,14 +69,6 @@ func TestInvalidChain(t *testing.T) {
8869
chainDir, err := ioutil.TempDir(name, "chain_")
8970
assert.Nil(t, err, "Error creating temp dir: %s", err)
9071

91-
t.Run("ChainDirNotReadable", func(t *testing.T) {
92-
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")
93-
assert.Nil(t, os.Chmod(chainDir, 0200), "Error chmod chain dir")
94-
defer os.Chmod(chainDir, 0700)
95-
assert.Panics(t, func() { New(name) }, "Expected initialization panics if chain dir is not readable")
96-
assert.Nil(t, os.Chmod(chainDir, 0700), "Error chmod chain dir")
97-
})
98-
9972
// Skip Block 0 to trigger MissingBlock error
10073
secondBlock := path.Join(chainDir, fmt.Sprintf(blockFileFormatString, 1))
10174
assert.NoError(t, ioutil.WriteFile(secondBlock, nil, 0700))
@@ -114,14 +87,6 @@ func TestInvalidChain(t *testing.T) {
11487
firstBlock := path.Join(chainDir, fmt.Sprintf(blockFileFormatString, 0))
11588
assert.NoError(t, ioutil.WriteFile(firstBlock, nil, 0700))
11689

117-
t.Run("BlockNotReadable", func(t *testing.T) {
118-
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")
119-
assert.NoError(t, os.Chmod(secondBlock, 0200))
120-
defer os.Chmod(secondBlock, 0700)
121-
assert.Panics(t, func() { New(name) }, "Expected initialization panics if block is not readable")
122-
assert.NoError(t, os.Chmod(secondBlock, 0700))
123-
})
124-
12590
t.Run("MalformedBlock", func(t *testing.T) {
12691
assert.Panics(t, func() { New(name) }, "Expected initialization panics if block is malformed")
12792
})
@@ -146,21 +111,6 @@ func TestIgnoreInvalidBlockFileName(t *testing.T) {
146111
assert.Zero(t, chain.Height(), "Expected chain to be empty")
147112
}
148113

149-
// This test checks that fs error causes creating chain to fail
150-
func TestErrorCreatingChain(t *testing.T) {
151-
t.Skip("Temporarily skip this test due to the reason stated at the top of this file")
152-
153-
name, err := ioutil.TempDir("", "hyperledger_fabric")
154-
assert.Nil(t, err, "Error creating temp dir: %s", err)
155-
defer os.RemoveAll(name)
156-
157-
jlf := New(name)
158-
assert.NoError(t, os.Chmod(name, 0400))
159-
defer os.Chmod(name, 0700)
160-
_, err = jlf.GetOrCreate(provisional.TestChainID)
161-
assert.Error(t, err, "Should have failed to create chain due to fs error")
162-
}
163-
164114
func TestClose(t *testing.T) {
165115
name, err := ioutil.TempDir("", "hyperledger_fabric")
166116
assert.Nil(t, err, "Error creating temp dir: %s", err)

0 commit comments

Comments
 (0)