@@ -17,14 +17,12 @@ limitations under the License.
17
17
package jsonledger
18
18
19
19
import (
20
- "testing"
21
-
22
20
"fmt"
23
21
"io/ioutil"
24
22
"os"
25
23
"path"
24
+ "testing"
26
25
27
- "github.com/hyperledger/fabric/common/configtx/tool/provisional"
28
26
logging "github.com/op/go-logging"
29
27
"github.com/stretchr/testify/assert"
30
28
)
@@ -33,10 +31,6 @@ func init() {
33
31
logging .SetLevel (logging .DEBUG , "" )
34
32
}
35
33
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
-
40
34
// This test checks that `New` factory should fail if parent directory is read-only
41
35
func TestErrorMkdir (t * testing.T ) {
42
36
name , err := ioutil .TempDir ("" , "hyperledger_fabric" )
@@ -48,19 +42,6 @@ func TestErrorMkdir(t *testing.T) {
48
42
assert .Panics (t , func () { New (ledgerPath ) }, "Should have failed to create factory" )
49
43
}
50
44
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
-
64
45
// This test checks that factory initialization should ignore dir with invalid name and files.
65
46
// NOTE: unfortunately this test does not really test intended logic because errors caused by
66
47
// constructing a chain from invalid dir or file are ignored anyway. Consider refactoring impl
@@ -88,14 +69,6 @@ func TestInvalidChain(t *testing.T) {
88
69
chainDir , err := ioutil .TempDir (name , "chain_" )
89
70
assert .Nil (t , err , "Error creating temp dir: %s" , err )
90
71
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
-
99
72
// Skip Block 0 to trigger MissingBlock error
100
73
secondBlock := path .Join (chainDir , fmt .Sprintf (blockFileFormatString , 1 ))
101
74
assert .NoError (t , ioutil .WriteFile (secondBlock , nil , 0700 ))
@@ -114,14 +87,6 @@ func TestInvalidChain(t *testing.T) {
114
87
firstBlock := path .Join (chainDir , fmt .Sprintf (blockFileFormatString , 0 ))
115
88
assert .NoError (t , ioutil .WriteFile (firstBlock , nil , 0700 ))
116
89
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
-
125
90
t .Run ("MalformedBlock" , func (t * testing.T ) {
126
91
assert .Panics (t , func () { New (name ) }, "Expected initialization panics if block is malformed" )
127
92
})
@@ -146,21 +111,6 @@ func TestIgnoreInvalidBlockFileName(t *testing.T) {
146
111
assert .Zero (t , chain .Height (), "Expected chain to be empty" )
147
112
}
148
113
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
-
164
114
func TestClose (t * testing.T ) {
165
115
name , err := ioutil .TempDir ("" , "hyperledger_fabric" )
166
116
assert .Nil (t , err , "Error creating temp dir: %s" , err )
0 commit comments