-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "[FAB-2976] Server shouldn't create dup affiliations"
- Loading branch information
Showing
6 changed files
with
121 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package lib | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-ca/lib/spi" | ||
) | ||
|
||
const ( | ||
serverPort = 7060 | ||
affiliationName = "org1" | ||
) | ||
|
||
// TestGetAffliation checks if there is one record for the | ||
// affilition 'org1' in the database after starting the server | ||
// two times. This test is to make sure server does not create | ||
// duplicate affiliations in the database every time it is | ||
// started. | ||
func TestGetAffliation(t *testing.T) { | ||
// Start the server at an available port (using port 0 will make OS to | ||
// pick an available port) | ||
srv := getServer(serverPort, testdataDir, "", 0, t) | ||
|
||
err := srv.Start() | ||
if err != nil { | ||
t.Fatalf("Server start failed: %v", err) | ||
} | ||
err = srv.Stop() | ||
if err != nil { | ||
t.Fatalf("Server stop failed: %v", err) | ||
} | ||
|
||
err = srv.Start() | ||
if err != nil { | ||
t.Fatalf("Server start failed: %v", err) | ||
} | ||
defer srv.Stop() | ||
|
||
afs := []spi.AffiliationImpl{} | ||
err = srv.db.Select(&afs, srv.db.Rebind(getAffiliation), affiliationName) | ||
t.Logf("Retrieved %+v for the affiliation %s", afs, affiliationName) | ||
if err != nil { | ||
t.Fatalf("Failed to get affiliation %s: %v", affiliationName, err) | ||
} | ||
if len(afs) != 1 { | ||
t.Fatalf("Found 0 or more than one record for the affiliation %s in the database, expected 1 record", affiliationName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters