diff --git a/flake.nix b/flake.nix index 5df16a9..8bb232e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,9 @@ pkgs = nixpkgs.legacyPackages.x86_64-linux; in { + packages.x86_64-linux = { + default = pkgs.callPackage ./nix/secret-santa.nix { }; + }; /* packages.x86_64-linux.default = pkgs.dockerTools.buildLayeredImage { name = "secret-santa"; diff --git a/internal/config/db_config.go b/internal/config/db_config.go index 3475b46..a0806a9 100644 --- a/internal/config/db_config.go +++ b/internal/config/db_config.go @@ -85,7 +85,6 @@ func (c *DatabaseConfig) GetDriver() string { default: return "" } - return string(c.Driver) } func (c *DatabaseConfig) generateSQLiteDSN() string { diff --git a/internal/handlers/user_handler_test.go b/internal/handlers/user_handler_test.go index 15ddc8d..bca8b36 100644 --- a/internal/handlers/user_handler_test.go +++ b/internal/handlers/user_handler_test.go @@ -3,6 +3,7 @@ package handlers_test import ( "context" "git.katuwoss.dev/JustScreaMy/secret-santa/internal/testhelpers" + _ "github.com/jackc/pgx/v5/stdlib" "github.com/stretchr/testify/assert" "testing" ) @@ -11,7 +12,9 @@ import ( func TestHandleGetUsers(t *testing.T) { ctx := context.Background() database, err := testhelpers.CreatePostgresContainer(ctx) + t.Log(database.ConnectionString) + assert.NoError(t, err) - err = testhelpers.MigrateDatabase("postgres", database.ConnectionString) + err = testhelpers.MigrateDatabase("pgx", "postgres", database.ConnectionString) assert.NoError(t, err) } diff --git a/internal/testhelpers/containers.go b/internal/testhelpers/containers.go index cda6063..010b655 100644 --- a/internal/testhelpers/containers.go +++ b/internal/testhelpers/containers.go @@ -13,7 +13,7 @@ type PostgresContainer struct { } func CreatePostgresContainer(ctx context.Context) (*PostgresContainer, error) { - container, err := postgres.Run(ctx, "16", + container, err := postgres.Run(ctx, "docker.io/postgres:16-alpine", postgres.WithUsername("test-user"), postgres.WithPassword("test-password"), postgres.WithDatabase("test-db"), diff --git a/internal/testhelpers/migrations.go b/internal/testhelpers/migrations.go index 1607730..8671777 100644 --- a/internal/testhelpers/migrations.go +++ b/internal/testhelpers/migrations.go @@ -5,15 +5,15 @@ import ( "github.com/rubenv/sql-migrate" ) -func MigrateDatabase(databaseDriver string, connectionString string) error { +func MigrateDatabase(databaseDriver, databaseDialect, connectionString string) error { db, err := sql.Open(databaseDriver, connectionString) if err != nil { return err } migrations := &migrate.FileMigrationSource{ - Dir: "sql/migrations", + Dir: "../../sql/migrations", } - _, err = migrate.Exec(db, databaseDriver, migrations, migrate.Up) + _, err = migrate.Exec(db, databaseDialect, migrations, migrate.Up) return err } diff --git a/nix/secret-santa.nix b/nix/secret-santa.nix new file mode 100644 index 0000000..5c5dacf --- /dev/null +++ b/nix/secret-santa.nix @@ -0,0 +1,24 @@ +{ + buildGoModule, + lib, +}: +buildGoModule rec { + pname = "secret-santa"; + version = "0.0.1"; + + src = ./..; + + vendorHash = "sha256-ZxzjlqylSkQ9Bj0y0eOJYHCuoPKBOtQcpFgGrkAlbr8="; + + ldflags = [ + "-s" + "-w" + ]; + doCheck = false; + + meta = with lib; { + homepage = "https://git.katuwoss.dev/JustScreaMy/secret-santa"; + description = "Secret-santa manager"; + license = licenses.mit; + }; +}