Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Feb 1, 2024
1 parent 42d5a8c commit 22d5182
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions comid/integregisters.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (i *IntegReg) AddDigests(index IRegisterIndex, digests Digests) error {

// AddDigest allows inserting a Digest at a specific RegisterIndex
func (i *IntegReg) AddDigest(index IRegisterIndex, digest swid.HashEntry) error {

if i.Register == nil {
return fmt.Errorf("no register to add digest")
}
switch t := index.(type) {
case string, uint, uint64:
i.Register[t] = append(i.Register[t], digest)
Expand Down
14 changes: 13 additions & 1 deletion comid/integregisters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,26 @@ func TestIntegRegister_AddDigest_OK(t *testing.T) {
}

func TestIntegRegister_AddDigest_NOK(t *testing.T) {
expectedErr := `unexpected type for index: bool`
expectedErr := `no register to add digest`
register := IntegReg{}
err := register.AddDigest(uint(0), swid.HashEntry{})
assert.EqualError(t, err, expectedErr)

expectedErr = `unexpected type for index: bool`
var k bool
reg, err := prepareRegister("uint")
require.NoError(t, err)
err = reg.AddDigest(k, swid.HashEntry{})
assert.EqualError(t, err, expectedErr)
}

func TestIntegRegister_AddDigests_NOK(t *testing.T) {
expectedErr := `no digests to add`
register := IntegReg{}
err := register.AddDigests(uint(0), []swid.HashEntry{})
assert.EqualError(t, err, expectedErr)
}

func TestIntegRegister_UInt_MarshalCBOR_OK(t *testing.T) {
reg, err := prepareRegister("uint")
require.NoError(t, err)
Expand Down

0 comments on commit 22d5182

Please sign in to comment.