Skip to content

Commit

Permalink
Add unit tests for registering release service with server
Browse files Browse the repository at this point in the history
  • Loading branch information
vmilovanovicc committed Nov 14, 2023
1 parent 26849db commit d92ab18
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ services:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
#- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_EXPORTER_OTLP_ENDPOINT
ports:
- 50007:3001
networks:
Expand Down
68 changes: 68 additions & 0 deletions internal/release/services/release/release_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package release

import (
"errors"
"testing"

"github.com/terrariumcloud/terrarium/internal/storage/mocks"

"google.golang.org/grpc"
)

// Test_RegisterReleaseWithServer checks:
// - if there was no error with table init
// - if error is returned when Table initialization fails
func Test_RegisterReleaseWithServer(t *testing.T) {
t.Parallel()

t.Run("when there is no error with table init", func(t *testing.T) {
db := &mocks.DynamoDB{}

rs := &ReleaseService{
Db: db,
}

s := grpc.NewServer(*new([]grpc.ServerOption)...)

err := rs.RegisterWithServer(s)

if err != nil {
t.Errorf("Expected no error, got %v.", err)
}

if db.DescribeTableInvocations != 1 {
t.Errorf("Expected 1 call to DescribeTable, got %v.", db.DescribeTableInvocations)
}

if db.CreateTableInvocations != 0 {
t.Errorf("Expected no calls to CreateTable, got %v.", db.CreateTableInvocations)
}
})

t.Run("when Table initialization fails", func(t *testing.T) {

db := &mocks.DynamoDB{
DescribeTableErrors: []error{errors.New("some error")},
}

rs := &ReleaseService{
Db: db,
}

s := grpc.NewServer(*new([]grpc.ServerOption)...)

err := rs.RegisterWithServer(s)

if err != ReleaseTableInitializationError {
t.Errorf("Expected %v, got %v.", ReleaseTableInitializationError, err)
}

if db.DescribeTableInvocations != 1 {
t.Errorf("Expected 1 call to DescribeTable, got %v.", db.DescribeTableInvocations)
}

if db.CreateTableInvocations != 0 {
t.Errorf("Expected 0 calls to CreateTable, got %v.", db.CreateTableInvocations)
}
})
}

0 comments on commit d92ab18

Please sign in to comment.