-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minoch: extend coverage of unit tests
- Loading branch information
1 parent
380d814
commit d7e13bf
Showing
7 changed files
with
217 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package minoch | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.dedis.ch/fabric/internal/testing/fake" | ||
"go.dedis.ch/fabric/mino" | ||
) | ||
|
||
func TestManager_Get(t *testing.T) { | ||
manager := &Manager{ | ||
instances: map[string]*Minoch{"A": {}}, | ||
} | ||
|
||
m, err := manager.get(address{id: "A"}) | ||
require.NoError(t, err) | ||
require.NotNil(t, m) | ||
|
||
_, err = manager.get(address{id: "B"}) | ||
require.EqualError(t, err, "address <B> not found") | ||
|
||
_, err = manager.get(fake.NewBadAddress()) | ||
require.EqualError(t, err, "invalid address type 'fake.Address'") | ||
} | ||
|
||
func TestManager_Insert(t *testing.T) { | ||
manager := NewManager() | ||
|
||
err := manager.insert(&Minoch{identifier: "A"}) | ||
require.NoError(t, err) | ||
|
||
err = manager.insert(&Minoch{identifier: "A"}) | ||
require.EqualError(t, err, "identifier <A> already exists") | ||
|
||
err = manager.insert(&Minoch{}) | ||
require.EqualError(t, err, "cannot have an empty identifier") | ||
|
||
err = manager.insert(fakeInstance{}) | ||
require.EqualError(t, err, "invalid instance type 'minoch.fakeInstance'") | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Utility functions | ||
|
||
type fakeInstance struct { | ||
mino.Mino | ||
} |
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
Oops, something went wrong.