Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and build on PR #60

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and run tests
on:
push:
branches:
- main

pull_request:

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v3
with:
stable: 'true'
go-version: 1.21

- name: Test Code
run: |
export CI=true
go test './...'
echo "Tests passed successfully."

- name: Build
run: |
go build
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (srv *MockRetrieveContainerDependenciesServer) Send(res *terrarium.Containe
return srv.Err
}

func (src *MockRetrieveContainerDependenciesServer) Context() context.Context {
return context.TODO()
}

type MockRetrieveModuleDependenciesServer struct {
grpc.ServerStream
SendInvocations int
Expand All @@ -72,6 +76,10 @@ func (srv *MockRetrieveModuleDependenciesServer) Send(res *terrarium.ModuleDepen
return srv.Err
}

func (src *MockRetrieveModuleDependenciesServer) Context() context.Context {
return context.TODO()
}

type MockGetDependenciesResponse struct {
Dependencies []*terrarium.Module
Err error
Expand Down Expand Up @@ -123,10 +131,13 @@ func Test_RegisterDependencyManagerWithServer(t *testing.T) {
// - Module dependencies will fail...
// - Container dependencies
expectedDescribeTableInvocations := 1
expectedCreateTableInvocations := 0
expectedCreateTableInvocations := 1
expectedError := ModuleDependenciesTableInitializationError

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

dms := &DependencyManagerService{Db: db}

Expand All @@ -153,9 +164,12 @@ func Test_RegisterDependencyManagerWithServer(t *testing.T) {
// - Container dependencies will fail...
expectedError := ContainerDependenciesTableInitializationError
expectedDescribeTableInvocations := 2
expectedCreateTableInvocations := 0
expectedCreateTableInvocations := 1

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

dms := &DependencyManagerService{Db: db}

Expand Down
5 changes: 3 additions & 2 deletions internal/module/services/registrar/registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func Test_RegisterRegistrarWithServer(t *testing.T) {

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

rs := &RegistrarService{
Expand All @@ -235,8 +236,8 @@ func Test_RegisterRegistrarWithServer(t *testing.T) {
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)
if db.CreateTableInvocations != 1 {
t.Errorf("Expected 1 calls to CreateTable, got %v.", db.CreateTableInvocations)
}
})
}
5 changes: 3 additions & 2 deletions internal/module/services/tag_manager/tag_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func Test_RegisterTagManagerWithServer(t *testing.T) {

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

tm := &TagManagerService{
Expand All @@ -63,8 +64,8 @@ func Test_RegisterTagManagerWithServer(t *testing.T) {
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)
if db.CreateTableInvocations != 1 {
t.Errorf("Expected 1 calls to CreateTable, got %v.", db.CreateTableInvocations)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func Test_RegisterVersionManagerWithServer(t *testing.T) {
})

t.Run("when Table initialization fails", func(t *testing.T) {
db := &mocks.DynamoDB{DescribeTableErrors: []error{errors.New("some error")}}
db := &mocks.DynamoDB{
DescribeTableErrors: []error{errors.New("some error")},
CreateTableError: errors.New("some error"),
}

vms := &VersionManagerService{Db: db}

Expand All @@ -60,8 +63,8 @@ func Test_RegisterVersionManagerWithServer(t *testing.T) {
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)
if db.CreateTableInvocations != 1 {
t.Errorf("Expected 1 calls to CreateTable, got %v.", db.CreateTableInvocations)
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions internal/release/services/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func Test_RegisterReleaseWithServer(t *testing.T) {

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

rs := &ReleaseService{
Expand All @@ -74,8 +75,8 @@ func Test_RegisterReleaseWithServer(t *testing.T) {
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)
if db.CreateTableInvocations != 1 {
t.Errorf("Expected 1 calls to CreateTable, got %v.", db.CreateTableInvocations)
}
})
}
Expand Down
9 changes: 2 additions & 7 deletions internal/storage/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func Test_InitializeDynamoDb(t *testing.T) {
t.Run("when checking for table existence fails", func(t *testing.T) {
table := "Test"
schema := &dynamodb.CreateTableInput{}
someError := errors.New("some error")
db := &mocks.DynamoDB{
DescribeTableErrors: []error{errors.New("some error")},
}
Expand All @@ -85,12 +84,8 @@ func Test_InitializeDynamoDb(t *testing.T) {
t.Errorf("Expected %v, got %v.", table, db.TableName)
}

if err == nil {
t.Error("Expected error, got nil.")
}

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

Expand Down
Loading