Skip to content

Commit

Permalink
Merge "[FAB-5426] Fix unit-tests on vagrant/windows"
Browse files Browse the repository at this point in the history
  • Loading branch information
hacera-jonathan authored and Gerrit Code Review committed Sep 29, 2017
2 parents eeb12bd + 2780ccb commit 9ee95a3
Show file tree
Hide file tree
Showing 4 changed files with 448 additions and 156 deletions.
16 changes: 8 additions & 8 deletions lib/ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ func TestCAInit(t *testing.T) {
}
ca.Config.CA.Keyfile = caKey
ca.Config.CA.Certfile = caCert
err = os.Link("../ec256-1-key.pem", caKey)
err = CopyFile("../ec256-1-key.pem", caKey)
if err != nil {
t.Fatal("symlink error: ", err)
t.Fatal("Failed to copy file: ", err)
}
err = os.Link("../ec256-2-cert.pem", caCert)
err = CopyFile("../ec256-2-cert.pem", caCert)
if err != nil {
t.Fatal("symlink error: ", err)
t.Fatal("Failed to copy file: ", err)
}
err = ca.init(false)
t.Logf("init err: %v", err)
Expand Down Expand Up @@ -317,13 +317,13 @@ func TestCAInit(t *testing.T) {
if err != nil {
t.Fatalf("os.Remove failed: %v", err)
}
err = os.Link("../rsa2048-1-key.pem", caKey)
err = CopyFile("../rsa2048-1-key.pem", caKey)
if err != nil {
t.Fatal("symlink error: ", err)
t.Fatal("Failed to copy file: ", err)
}
err = os.Link("../rsa2048-1-cert.pem", caCert)
err = CopyFile("../rsa2048-1-cert.pem", caCert)
if err != nil {
t.Fatal("symlink error: ", err)
t.Fatal("Failed to copy file: ", err)
}
ca.Config.CA.Keyfile = caKey
ca.Config.CA.Certfile = caCert
Expand Down
13 changes: 11 additions & 2 deletions lib/dasqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func TestDBCreation(t *testing.T) {
testWithExistingDbAndTable(t)
testWithExistingDb(t)

os.Remove(rootDB)
err := os.Remove(rootDB)
if err != nil {
t.Errorf("Remove failed: %s", err)
}
}

func createSQLiteDB(path string, t *testing.T) (*sqlx.DB, *TestAccessor) {
Expand Down Expand Up @@ -159,6 +162,8 @@ func testWithExistingDbAndTablesAndUser(t *testing.T) {
err = srv.Stop()
assert.NoError(t, err, "Failed to stop server")

err = db.Close()
assert.NoError(t, err, "Failed to close DB")
}

// Test starting a server with an already existing database and tables, but not bootstrapped
Expand All @@ -183,14 +188,16 @@ func testWithExistingDbAndTable(t *testing.T) {
err = srv.Stop()
assert.NoError(t, err, "Failed to stop server")

err = db.Close()
assert.NoError(t, err, "Failed to close DB")
}

// Test starting a server with an already existing database, but no tables or users
func testWithExistingDb(t *testing.T) {
var err error

os.Remove(rootDB)
_, acc := createSQLiteDB(rootDB, t)
db, acc := createSQLiteDB(rootDB, t)

srv := TestGetServer2(false, rootPort, rootDir, "", -1, t)
srv.CA.Config.DB.Datasource = "fabric_ca.db"
Expand All @@ -204,6 +211,8 @@ func testWithExistingDb(t *testing.T) {
err = srv.Stop()
assert.NoError(t, err, "Failed to stop server")

err = db.Close()
assert.NoError(t, err, "Failed to close DB")
}

func removeDatabase() {
Expand Down
Loading

0 comments on commit 9ee95a3

Please sign in to comment.