diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3941edc..b306bd9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,35 +4,6 @@ run-name: Triggered by ${{ github.event_name }} to ${{ github.ref }} by @${{ git on: [push] jobs: - go_unit_test: - runs-on: ubuntu-latest - name: unit - defaults: - run: - shell: bash - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: true - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: '1.22.0' - - name: Install dependencies - run: | - go get . - - name: Run tests - run: | - make test - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - with: - files: coverage.out - verbose: true - web_lint_check: runs-on: ubuntu-latest name: web lint diff --git a/README.md b/README.md index 0e90bf6..d23f29e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![build](https://github.com/Gaucho-Racing/Sentinel/actions/workflows/build.yml/badge.svg)](https://github.com/Gaucho-Racing/Sentinel/actions/workflows/build.yml) [![Netlify Status](https://api.netlify.com/api/v1/badges/d64e59b0-b1eb-4668-a165-b4177a0fe6b6/deploy-status)](https://app.netlify.com/sites/gr-sentinel/deploys) -[![codecov](https://codecov.io/gh/Gaucho-Racing/Sentinel/graph/badge.svg?token=3X1TIS1C3X)](https://codecov.io/gh/Gaucho-Racing/Sentinel) [![Docker Pulls](https://img.shields.io/docker/pulls/gauchoracing/sentinel?style=flat-square)](https://hub.docker.com/r/gauchoracing/sentinel) [![Release](https://img.shields.io/github/release/gaucho-racing/sentinel.svg?style=flat-square)](https://github.com/gaucho-racing/sentinel/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index ee8fde8..0000000 --- a/codecov.yml +++ /dev/null @@ -1,8 +0,0 @@ -ignore: - - "main.go" - - "commands/" - - "config/" - - "jobs/" - - "model/" - - "controller/" - - "service/" \ No newline at end of file diff --git a/database/db_test.go b/database/db_test.go deleted file mode 100644 index 99ed68a..0000000 --- a/database/db_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package database - -import ( - "context" - "log" - "sentinel/config" - "sentinel/utils" - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/testcontainers/testcontainers-go/modules/mysql" - "go.uber.org/zap" - "gorm.io/gorm" -) - -func TestInitializeDB(t *testing.T) { - // Initialize logger - logger, _ := zap.NewDevelopment() - utils.SugarLogger = logger.Sugar() - - // Start MySQL container - ctx := context.Background() - - mysqlContainer, err := mysql.Run(ctx, - "mysql:8.0.36", - mysql.WithDatabase(config.DatabaseName), - mysql.WithUsername(config.DatabaseUser), - mysql.WithPassword(config.DatabasePassword), - ) - if err != nil { - log.Fatalf("failed to start container: %s", err) - } - - port, err := mysqlContainer.MappedPort(ctx, "3306/tcp") - if err != nil { - log.Fatalf("failed to get container port: %s", err) - } - - host, err := mysqlContainer.Host(ctx) - if err != nil { - log.Fatalf("failed to get container host: %s", err) - } - - config.DatabaseHost = host - config.DatabasePort = port.Port() - - // Clean up the container - defer func() { - if err := mysqlContainer.Terminate(ctx); err != nil { - log.Fatalf("failed to terminate container: %s", err) - } - }() - - // Test successful connection - t.Run("Successful Connection", func(t *testing.T) { - InitializeDB() - assert.NotNil(t, DB, "DB should not be nil after successful connection") - assert.IsType(t, &gorm.DB{}, DB, "DB should be of type *gorm.DB") - }) - - // Test retry mechanism - t.Run("Retry Mechanism", func(t *testing.T) { - config.DatabaseHost = "non-existent-host" - - done := make(chan bool) - go func() { - InitializeDB() - done <- true - }() - - select { - case <-done: - t.Error("InitializeDB should not have succeeded with non-existent host") - case <-time.After(10 * time.Second): - // Test passes if it times out after 10 seconds - } - }) -} diff --git a/utils/config_test.go b/utils/config_test.go deleted file mode 100644 index 4a3c4b6..0000000 --- a/utils/config_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package utils - -import ( - "sentinel/config" - "testing" -) - -func TestVerifyConfig(t *testing.T) { - InitializeLogger() - t.Run("Test Blank Config", func(t *testing.T) { - config.Env = "" - config.Port = "" - config.DatabaseHost = "" - config.DatabasePort = "" - config.DatabaseUser = "" - config.DatabasePassword = "" - config.DiscordToken = "" - config.DiscordGuild = "" - config.DiscordLogChannel = "" - config.GithubToken = "" - VerifyConfig() - }) -} diff --git a/utils/logger_test.go b/utils/logger_test.go deleted file mode 100644 index acea2ef..0000000 --- a/utils/logger_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package utils - -import ( - "sentinel/config" - "testing" -) - -func TestInitializeLogger(t *testing.T) { - t.Run("Logger Test 1", func(t *testing.T) { - config.Env = "DEV" - InitializeLogger() - if Logger == nil { - t.Error("Expected Logger to not be nil") - } - if SugarLogger == nil { - t.Error("Expected SugarLogger to not be nil") - } - }) - t.Run("Logger Test 2", func(t *testing.T) { - config.Env = "PROD" - InitializeLogger() - if Logger == nil { - t.Error("Expected Logger to not be nil") - } - if SugarLogger == nil { - t.Error("Expected SugarLogger to not be nil") - } - }) -} diff --git a/utils/roles_test.go b/utils/roles_test.go deleted file mode 100644 index 94f10b3..0000000 --- a/utils/roles_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package utils - -import ( - "sentinel/config" - "testing" -) - -func TestIsAdmin(t *testing.T) { - t.Run("Test Not Admin", func(t *testing.T) { - roles := []string{"1", "2", "3"} - if IsAdmin(roles) { - t.Error("Expected IsAdmin to return false") - } - }) - t.Run("Test Is Admin", func(t *testing.T) { - roles := []string{config.AdminRoleID, "2", "3", "4"} - if !IsAdmin(roles) { - t.Error("Expected IsAdmin to return true") - } - }) -} - -func TestIsOfficer(t *testing.T) { - t.Run("Test Not Officer", func(t *testing.T) { - roles := []string{"1", "2", "3"} - if IsOfficer(roles) { - t.Error("Expected IsOfficer to return false") - } - }) - t.Run("Test Is Officer", func(t *testing.T) { - roles := []string{config.OfficerRoleID, "2", "3", "4"} - if !IsOfficer(roles) { - t.Error("Expected IsOfficer to return true") - } - }) -} - -func TestIsLead(t *testing.T) { - t.Run("Test Not Lead", func(t *testing.T) { - roles := []string{"1", "2", "3"} - if IsLead(roles) { - t.Error("Expected IsLead to return false") - } - }) - t.Run("Test Is Lead", func(t *testing.T) { - roles := []string{config.LeadRoleID, "2", "3", "4"} - if !IsLead(roles) { - t.Error("Expected IsLead to return true") - } - }) -} - -func TestIsInnerCircle(t *testing.T) { - t.Run("Test Not Inner Circle", func(t *testing.T) { - roles := []string{"1", "2", "3"} - if IsInnerCircle(roles) { - t.Error("Expected IsInnerCircle to return false") - } - }) - t.Run("Test Is Inner Circle", func(t *testing.T) { - roles := []string{config.AdminRoleID, config.OfficerRoleID, "4"} - if !IsInnerCircle(roles) { - t.Error("Expected IsInnerCircle to return true") - } - }) -} diff --git a/utils/time_test.go b/utils/time_test.go deleted file mode 100644 index 191b565..0000000 --- a/utils/time_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package utils - -import ( - "testing" - "time" -) - -func TestWithPrecision(t *testing.T) { - tests := []struct { - name string - input time.Time - expected time.Time - }{ - { - name: "Round to microsecond precision", - input: time.Date(2023, 4, 15, 12, 30, 45, 123456789, time.UTC), - expected: time.Date(2023, 4, 15, 12, 30, 45, 123457000, time.UTC), - }, - { - name: "Already at microsecond precision", - input: time.Date(2023, 4, 15, 12, 30, 45, 123000000, time.UTC), - expected: time.Date(2023, 4, 15, 12, 30, 45, 123000000, time.UTC), - }, - { - name: "Round up to next microsecond", - input: time.Date(2023, 4, 15, 12, 30, 45, 123999999, time.UTC), - expected: time.Date(2023, 4, 15, 12, 30, 45, 124000000, time.UTC), - }, - { - name: "Round down to previous microsecond", - input: time.Date(2023, 4, 15, 12, 30, 45, 123000001, time.UTC), - expected: time.Date(2023, 4, 15, 12, 30, 45, 123000000, time.UTC), - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := WithPrecision(tt.input) - if !result.Equal(tt.expected) { - t.Errorf("WithPrecision(%v) = %v, want %v", tt.input, result, tt.expected) - } - }) - } -}