diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..3f7b788 --- /dev/null +++ b/.github/workflows/pr.yml @@ -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 \ No newline at end of file diff --git a/internal/module/services/dependency_manager/dependency_manager_test.go b/internal/module/services/dependency_manager/dependency_manager_test.go index 59f5351..5645cff 100644 --- a/internal/module/services/dependency_manager/dependency_manager_test.go +++ b/internal/module/services/dependency_manager/dependency_manager_test.go @@ -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 @@ -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 @@ -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} @@ -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} diff --git a/internal/module/services/registrar/registrar_test.go b/internal/module/services/registrar/registrar_test.go index 5ad8bce..67fd3b0 100644 --- a/internal/module/services/registrar/registrar_test.go +++ b/internal/module/services/registrar/registrar_test.go @@ -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{ @@ -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) } }) } diff --git a/internal/module/services/tag_manager/tag_manager_test.go b/internal/module/services/tag_manager/tag_manager_test.go index 8e4a4f9..fd6b6cc 100644 --- a/internal/module/services/tag_manager/tag_manager_test.go +++ b/internal/module/services/tag_manager/tag_manager_test.go @@ -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{ @@ -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) } }) } diff --git a/internal/module/services/version_manager/version_manager_test.go b/internal/module/services/version_manager/version_manager_test.go index 9d57bde..276bd7d 100644 --- a/internal/module/services/version_manager/version_manager_test.go +++ b/internal/module/services/version_manager/version_manager_test.go @@ -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} @@ -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) } }) } diff --git a/internal/release/services/release/release_test.go b/internal/release/services/release/release_test.go index 0e915f6..3fd1a19 100644 --- a/internal/release/services/release/release_test.go +++ b/internal/release/services/release/release_test.go @@ -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{ @@ -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) } }) } diff --git a/internal/storage/dynamodb_test.go b/internal/storage/dynamodb_test.go index 87faa17..f0c7042 100644 --- a/internal/storage/dynamodb_test.go +++ b/internal/storage/dynamodb_test.go @@ -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")}, } @@ -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) } })