Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Addded a validation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 committed Jan 3, 2023
1 parent ba5409b commit 9b218be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/service/operation/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Storage interface {
CancelOperation(id string) (*StoredOperation, error)
}

// StatusObjectID attempts to parse the submission id from the StatusObjectID of the operation. This is done by taking the last word
// StatusObjectID attempts to parse the submission id from the ID of the operation. This is done by taking the last word
// that results from splitting the id by "/". On failures, the empty string is returned.
func StatusObjectID(opID string) string {
i := strings.LastIndex(opID, "/")
Expand Down
30 changes: 22 additions & 8 deletions pkg/service/operation/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
storage2 "github.com/tbd54566975/ssi-service/pkg/service/manifest/storage"
manifeststg "github.com/tbd54566975/ssi-service/pkg/service/manifest/storage"
"github.com/tbd54566975/ssi-service/pkg/service/operation/credential"
opstorage "github.com/tbd54566975/ssi-service/pkg/service/operation/storage"
"github.com/tbd54566975/ssi-service/pkg/service/operation/storage/namespace"
Expand All @@ -31,15 +31,9 @@ func setupTestDB(t *testing.T) storage.ServiceStorage {

func TestStorage_CancelOperation(t *testing.T) {
s := setupTestDB(t)
data, err := json.Marshal(storage2.StoredApplication{})
data, err := json.Marshal(manifeststg.StoredApplication{})
require.NoError(t, err)
require.NoError(t, s.Write(credential.ApplicationNamespace, "hello", data))
opData, err := json.Marshal(opstorage.StoredOperation{
ID: "credentials/responses/hello",
Done: false,
})
require.NoError(t, err)
require.NoError(t, s.Write(namespace.FromParent("credentials/responses"), "credentials/responses/hello", opData))

type fields struct {
db storage.ServiceStorage
Expand All @@ -53,6 +47,7 @@ func TestStorage_CancelOperation(t *testing.T) {
args args
want *opstorage.StoredOperation
wantErr bool
done bool
}{
{
name: "bad id returns error",
Expand All @@ -77,9 +72,28 @@ func TestStorage_CancelOperation(t *testing.T) {
Done: true,
},
},
{
name: "done operation returns error on cancellation",
done: true,
fields: fields{
db: s,
},
args: args{
id: "credentials/responses/hello",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

opData, err := json.Marshal(opstorage.StoredOperation{
ID: "credentials/responses/hello",
Done: tt.done,
})
require.NoError(t, err)
require.NoError(t, s.Write(namespace.FromParent("credentials/responses"), "credentials/responses/hello", opData))

b := Storage{
db: tt.fields.db,
}
Expand Down

0 comments on commit 9b218be

Please sign in to comment.