mirror of
https://github.com/gomods/athens
synced 2026-02-03 14:20:31 +00:00
Remove pop from Proxy & RDBMS storage getter (#511)
* Remove pop from models for now
* Remove rdbms storage from pkg/storage
* Completely remove pop
* Some improvements to tests
- Not sourcing from cmd/proxy/.env, because that doesn't export any variables
- Removing mysql support (I feel like 1 database is enough)
- Pruning networks on teardown
I'm happy to split these changes up into separate PRs - it's the end of the day for me so I wanted to get everything in 😄
* update to point to test instance
* Update databasy.yml for travis??
* Remove database.yml
* Do not use db migrations and creation
* Remove pop dependency from cdn
* add schema for olympus assuming cdn driver is part of olympus
* Move CI/CD and test scripts to point pop to olympus
* Update database.yml and keep it only for olympus
* Add migrations to travis
* Add debug logs to see what travis is doing
* Update travis to use olympus database.yml
* Moarrrr logs to see where travis is pointint the db towards
* Change env to test
* Use test as the default environment if not specified otherwise
* Check if test new rdbms storage succeeds
* Try to see which connection string rdbms test suite is using on travis
* Update db tags for cdn driver
* create db by using travis go_env
* Remove sql from database config as it is removed from docker-compose
* Remove extra logs that I missed
* Add newline
* remove models.go and test file from proxy
* removing extraneous network prune from Makefile
This commit is contained in:
committed by
Marwan Sulaiman
parent
c8b64fd258
commit
c0635b748c
+5
-4
@@ -7,8 +7,8 @@ go:
|
||||
env:
|
||||
global:
|
||||
- PATH=${PATH}:./bin
|
||||
- POP_PATH=$PWD/cmd/proxy
|
||||
- GO_ENV=test_postgres
|
||||
- POP_PATH=$PWD/cmd/olympus
|
||||
- GO_ENV=test
|
||||
- MINIO_ACCESS_KEY=minio
|
||||
- MINIO_SECRET_KEY=minio123
|
||||
- ATHENS_MONGO_CONNECTION_STRING=mongodb://127.0.0.1:27017
|
||||
@@ -20,8 +20,9 @@ before_script:
|
||||
- make setup-dev-env
|
||||
- wget "https://dl.minio.io/server/minio/release/linux-amd64/minio"
|
||||
- chmod +x minio && nohup ./minio server . &
|
||||
- buffalo db create
|
||||
- buffalo db migrate up
|
||||
- buffalo db create -e $GO_ENV -d -c $POP_PATH/database.yml
|
||||
- buffalo db migrate up -e $GO_ENV -d -c $POP_PATH/database.yml
|
||||
|
||||
|
||||
script:
|
||||
- make verify test-unit test-e2e
|
||||
|
||||
@@ -51,7 +51,6 @@ bench:
|
||||
|
||||
.PHONY: alldeps
|
||||
alldeps:
|
||||
docker-compose -p athensdev up -d mysql
|
||||
docker-compose -p athensdev up -d postgres
|
||||
docker-compose -p athensdev up -d mongo
|
||||
docker-compose -p athensdev up -d redis
|
||||
|
||||
@@ -109,11 +109,6 @@ func App(config *AppConfig) (*buffalo.App, error) {
|
||||
// TODO: initialize the azurecdn.Storage struct here
|
||||
}))
|
||||
|
||||
// Wraps each request in a transaction.
|
||||
// c.Value("tx").(*pop.PopTransaction)
|
||||
// Remove to disable this.
|
||||
// app.Use(middleware.PopTransaction(models.DB))
|
||||
|
||||
// Setup and use translations:
|
||||
if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil {
|
||||
app.Stop(err)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/gomods/athens/pkg/storage/fs"
|
||||
"github.com/gomods/athens/pkg/storage/mem"
|
||||
"github.com/gomods/athens/pkg/storage/mongo"
|
||||
"github.com/gomods/athens/pkg/storage/rdbms"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -35,12 +34,6 @@ func GetStorage() (storage.Backend, error) {
|
||||
}
|
||||
certPath := env.MongoCertPath()
|
||||
return mongo.NewStorageWithCert(connectionString, certPath)
|
||||
case "postgres", "sqlite", "cockroach", "mysql":
|
||||
connectionName, err := env.RdbmsName()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rdbms.NewRDBMSStorage(connectionName)
|
||||
default:
|
||||
return nil, fmt.Errorf("storage type %s is unknown", storageType)
|
||||
}
|
||||
|
||||
+11
-18
@@ -1,29 +1,22 @@
|
||||
development:
|
||||
dialect: "mysql"
|
||||
dialect: "postgres"
|
||||
database: athens
|
||||
host: 127.0.0.1
|
||||
port: 3306
|
||||
user: vgp
|
||||
password: vgp
|
||||
|
||||
test_postgres:
|
||||
dialect: "postgres"
|
||||
database: athens_development
|
||||
port: 5432
|
||||
user: postgres
|
||||
password: ''
|
||||
password: postgres
|
||||
|
||||
test:
|
||||
dialect: "postgres"
|
||||
database: athens_test
|
||||
user: postgres
|
||||
password: postgres
|
||||
port: 5432
|
||||
host: 127.0.0.1
|
||||
pool: 5
|
||||
|
||||
test:
|
||||
dialect: "mysql"
|
||||
database: athens
|
||||
host: 127.0.0.1
|
||||
port: 3306
|
||||
user: vgp
|
||||
password: vgp
|
||||
|
||||
production:
|
||||
dialect: "mysql"
|
||||
dialect: "postgres"
|
||||
database: olympusdb
|
||||
host: {{ env "DB_HOST" }}
|
||||
port: {{ env "DB_PORT" }}
|
||||
|
||||
@@ -1,40 +1,57 @@
|
||||
-- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64)
|
||||
--
|
||||
-- Host: 127.0.0.1 Database: athens
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 5.7.21
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `schema_migration`
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `schema_migration`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `schema_migration` (
|
||||
`version` varchar(255) NOT NULL,
|
||||
UNIQUE KEY `version_idx` (`version`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
-- Dumped from database version 9.6.9
|
||||
-- Dumped by pg_dump version 10.4
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
|
||||
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_with_oids = false;
|
||||
|
||||
--
|
||||
-- Name: schema_migration; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.schema_migration (
|
||||
version character varying(255) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.schema_migration OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: schema_migration_version_idx; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX schema_migration_version_idx ON public.schema_migration USING btree (version);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
-- Dump completed on 2018-06-06 12:42:59
|
||||
|
||||
@@ -1,22 +1,5 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/gobuffalo/pop"
|
||||
"github.com/gomods/athens/pkg/config/env"
|
||||
)
|
||||
|
||||
// DB is a connection to your database to be used
|
||||
// throughout your application.
|
||||
var DB *pop.Connection
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
env := env.GoEnvironmentWithDefault("development")
|
||||
DB, err = pop.Connect(env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pop.Debug = env == "development"
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,8 @@ package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gobuffalo/suite"
|
||||
)
|
||||
|
||||
type ModelSuite struct {
|
||||
*suite.Model
|
||||
}
|
||||
|
||||
func Test_ModelSuite(t *testing.T) {
|
||||
as := &ModelSuite{suite.NewModel()}
|
||||
suite.Run(t, as)
|
||||
|
||||
}
|
||||
|
||||
@@ -119,12 +119,6 @@ func App() (*buffalo.App, error) {
|
||||
csrfMiddleware := csrf.New
|
||||
app.Use(csrfMiddleware)
|
||||
}
|
||||
|
||||
// Wraps each request in a transaction.
|
||||
// c.Value("tx").(*pop.PopTransaction)
|
||||
// Remove to disable this.
|
||||
// app.Use(middleware.PopTransaction(models.DB))
|
||||
|
||||
// Setup and use translations:
|
||||
if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil {
|
||||
app.Stop(err)
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/gomods/athens/pkg/storage/mem"
|
||||
"github.com/gomods/athens/pkg/storage/minio"
|
||||
"github.com/gomods/athens/pkg/storage/mongo"
|
||||
"github.com/gomods/athens/pkg/storage/rdbms"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@@ -43,12 +42,6 @@ func GetStorage() (storage.Backend, error) {
|
||||
return nil, fmt.Errorf("could not create new storage from os fs (%s)", err)
|
||||
}
|
||||
return s, nil
|
||||
case "postgres", "sqlite", "cockroach", "mysql":
|
||||
storageRoot, err = env.RdbmsName()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rdbms.NewRDBMSStorage(storageRoot)
|
||||
case "minio":
|
||||
endpoint, err := env.MinioEndpoint()
|
||||
if err != nil {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
development:
|
||||
dialect: "mysql"
|
||||
database: athens
|
||||
host: 127.0.0.1
|
||||
port: 3306
|
||||
user: vgp
|
||||
password: vgp
|
||||
|
||||
test:
|
||||
dialect: "mysql"
|
||||
database: athens
|
||||
host: 127.0.0.1
|
||||
port: 3306
|
||||
user: vgp
|
||||
password: vgp
|
||||
|
||||
test_postgres:
|
||||
dialect: "postgres"
|
||||
database: athens_development
|
||||
user: postgres
|
||||
password: ''
|
||||
host: 127.0.0.1
|
||||
pool: 5
|
||||
|
||||
production:
|
||||
dialect: "mysql"
|
||||
database: olympusdb
|
||||
host: {{ env "DB_HOST" }}
|
||||
port: {{ env "DB_PORT" }}
|
||||
user: {{ env "DB_USER" }}
|
||||
password: {{ env "DB_PASS" }}
|
||||
@@ -1,22 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/gobuffalo/pop"
|
||||
"github.com/gomods/athens/pkg/config/env"
|
||||
)
|
||||
|
||||
// DB is a connection to your database to be used
|
||||
// throughout your application.
|
||||
var DB *pop.Connection
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
env := env.GoEnvironmentWithDefault("development")
|
||||
DB, err = pop.Connect(env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pop.Debug = env == "development"
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gobuffalo/suite"
|
||||
)
|
||||
|
||||
type ModelSuite struct {
|
||||
*suite.Model
|
||||
}
|
||||
|
||||
func Test_ModelSuite(t *testing.T) {
|
||||
as := &ModelSuite{suite.NewModel()}
|
||||
suite.Run(t, as)
|
||||
}
|
||||
+3
-9
@@ -9,19 +9,13 @@ services:
|
||||
image: mongo:3.7.9-jessie
|
||||
ports:
|
||||
- 27017:27017
|
||||
mysql:
|
||||
image: bitnami/mysql:5.7.21-r7
|
||||
ports:
|
||||
- "3306:3306"
|
||||
environment:
|
||||
- "ALLOW_EMPTY_PASSWORD=yes"
|
||||
- "MYSQL_USER=vgp"
|
||||
- "MYSQL_PASSWORD=vgp"
|
||||
- "MYSQL_DATABASE=athens"
|
||||
postgres:
|
||||
image: postgres:9.6.9-alpine
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
command: server /data
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 9.6.9
|
||||
-- Dumped by pg_dump version 10.4
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
|
||||
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_with_oids = false;
|
||||
|
||||
--
|
||||
-- Name: cdn_metadata_entries; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.cdn_metadata_entries (
|
||||
id uuid NOT NULL,
|
||||
module text NOT NULL,
|
||||
redirect_url text NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.cdn_metadata_entries OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: modules; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.modules (
|
||||
id uuid NOT NULL,
|
||||
module text NOT NULL,
|
||||
version text NOT NULL,
|
||||
mod bytea NOT NULL,
|
||||
zip bytea NOT NULL,
|
||||
info bytea NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.modules OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: schema_migration; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.schema_migration (
|
||||
version character varying(255) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.schema_migration OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: cdn_metadata_entries cdn_metadata_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.cdn_metadata_entries
|
||||
ADD CONSTRAINT cdn_metadata_entries_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: modules modules_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.modules
|
||||
ADD CONSTRAINT modules_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_migration_version_idx; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX schema_migration_version_idx ON public.schema_migration USING btree (version);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/gobuffalo/pop"
|
||||
"github.com/gobuffalo/uuid"
|
||||
"github.com/gobuffalo/validate"
|
||||
"github.com/gobuffalo/validate/validators"
|
||||
)
|
||||
|
||||
// CDNMetadataEntry stores the module name and cdn URL.
|
||||
@@ -19,36 +15,6 @@ type CDNMetadataEntry struct {
|
||||
RedirectURL string `json:"redirect_url" db:"redirect_url" bson:"redirect_url"`
|
||||
}
|
||||
|
||||
// String is not required by pop and may be deleted
|
||||
func (e CDNMetadataEntry) String() string {
|
||||
je, _ := json.Marshal(e)
|
||||
return string(je)
|
||||
}
|
||||
|
||||
// CdnMetadataEntries is not required by pop and may be deleted
|
||||
type CdnMetadataEntries []CDNMetadataEntry
|
||||
|
||||
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
|
||||
// This method is not required and may be deleted.
|
||||
func (e *CDNMetadataEntry) Validate(tx *pop.Connection) (*validate.Errors, error) {
|
||||
return validate.Validate(
|
||||
&validators.StringIsPresent{Field: e.Module, Name: "Module"},
|
||||
&validators.StringIsPresent{Field: e.RedirectURL, Name: "RedirectURL"},
|
||||
), nil
|
||||
}
|
||||
|
||||
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
|
||||
// This method is not required and may be deleted.
|
||||
func (e *CDNMetadataEntry) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
|
||||
return validate.NewErrors(), nil
|
||||
}
|
||||
|
||||
// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
|
||||
// This method is not required and may be deleted.
|
||||
func (e *CDNMetadataEntry) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
|
||||
return validate.NewErrors(), nil
|
||||
}
|
||||
|
||||
// TableName changes the default name which would be c_d_n_metadata_entry
|
||||
func (e *CDNMetadataEntry) TableName() string {
|
||||
return "cdn_metadata_entries"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/envy"
|
||||
)
|
||||
|
||||
func (rd *RDBMSTestSuite) TestGetSaveRoundTrip() {
|
||||
r := rd.Require()
|
||||
err := rd.storage.Save(module, redirectURL)
|
||||
@@ -12,7 +16,7 @@ func (rd *RDBMSTestSuite) TestGetSaveRoundTrip() {
|
||||
|
||||
func (rd *RDBMSTestSuite) TestNewRDBMSStorage() {
|
||||
r := rd.Require()
|
||||
e := "development"
|
||||
e := envy.Get("GO_ENV", "test")
|
||||
getterSaver := NewStorage(e)
|
||||
getterSaver.Connect()
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gobuffalo/suite"
|
||||
"github.com/gomods/athens/pkg/storage"
|
||||
)
|
||||
|
||||
type RDBMSTestSuite struct {
|
||||
*suite.Model
|
||||
storage storage.Backend
|
||||
}
|
||||
|
||||
func (rd *RDBMSTestSuite) SetupTest() {
|
||||
rd.storage = &ModuleStore{conn: rd.DB}
|
||||
rd.Model.SetupTest()
|
||||
}
|
||||
|
||||
func Test_ActionSuite(t *testing.T) {
|
||||
suite.Run(t, &RDBMSTestSuite{Model: suite.NewModel()})
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gomods/athens/pkg/storage/rdbms/models"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// Exists checks for a specific version of a module
|
||||
func (r *ModuleStore) Exists(ctx context.Context, module, vsn string) bool {
|
||||
sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Exists")
|
||||
defer sp.Finish()
|
||||
result := models.Module{}
|
||||
query := r.conn.Where("module = ?", module).Where("version = ?", vsn)
|
||||
count, err := query.Count(&result)
|
||||
|
||||
return err == nil && count > 0
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
"github.com/gomods/athens/pkg/storage/rdbms/models"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// Delete removes a specific version of a module.
|
||||
func (r *ModuleStore) Delete(ctx context.Context, module, version string) error {
|
||||
const op errors.Op = "rdbms.Delete"
|
||||
sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Delete")
|
||||
defer sp.Finish()
|
||||
if !r.Exists(ctx, module, version) {
|
||||
return errors.E(op, errors.M(module), errors.V(version), errors.KindNotFound)
|
||||
}
|
||||
result := &models.Module{}
|
||||
query := r.conn.Where("module = ?", module).Where("version = ?", version)
|
||||
if err := query.First(result); err != nil {
|
||||
return errors.E(op, err)
|
||||
}
|
||||
return r.conn.Destroy(result)
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
"github.com/gomods/athens/pkg/storage"
|
||||
"github.com/gomods/athens/pkg/storage/rdbms/models"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
pkgerrors "github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Get a specific version of a module
|
||||
func (r *ModuleStore) Get(ctx context.Context, module, vsn string) (*storage.Version, error) {
|
||||
const op errors.Op = "rdbms.Get"
|
||||
sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Get")
|
||||
defer sp.Finish()
|
||||
result := models.Module{}
|
||||
query := r.conn.Where("module = ?", module).Where("version = ?", vsn)
|
||||
if err := query.First(&result); err != nil {
|
||||
if pkgerrors.Cause(err) == sql.ErrNoRows { // can we just say err == sql.ErrNoRows?
|
||||
return nil, errors.E(op, errors.M(module), errors.V(vsn), errors.KindNotFound)
|
||||
}
|
||||
return nil, errors.E(op, err)
|
||||
}
|
||||
return &storage.Version{
|
||||
Mod: result.Mod,
|
||||
Zip: ioutil.NopCloser(bytes.NewReader(result.Zip)),
|
||||
Info: result.Info,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Info will panic.
|
||||
func (r *ModuleStore) Info(ctx context.Context, module, vsn string) ([]byte, error) {
|
||||
panic("")
|
||||
}
|
||||
|
||||
// GoMod will panic.
|
||||
func (r *ModuleStore) GoMod(ctx context.Context, module, vsn string) ([]byte, error) {
|
||||
panic("")
|
||||
}
|
||||
|
||||
// Zip will panic.
|
||||
func (r *ModuleStore) Zip(ctx context.Context, module, vsn string) (io.ReadCloser, error) {
|
||||
panic("")
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gomods/athens/pkg/storage/rdbms/models"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// List lists all versions of a module
|
||||
func (r *ModuleStore) List(ctx context.Context, module string) ([]string, error) {
|
||||
sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.List")
|
||||
defer sp.Finish()
|
||||
result := make([]models.Module, 0)
|
||||
err := r.conn.Where("module = ?", module).All(&result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
versions := make([]string, len(result))
|
||||
for i := range result {
|
||||
versions[i] = result[i].Version
|
||||
}
|
||||
|
||||
return versions, nil
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/gobuffalo/pop"
|
||||
"github.com/gobuffalo/uuid"
|
||||
"github.com/gobuffalo/validate"
|
||||
"github.com/gobuffalo/validate/validators"
|
||||
)
|
||||
|
||||
// Module is a model where data is stored.
|
||||
type Module struct {
|
||||
ID uuid.UUID `json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
||||
Module string `json:"module" db:"module"`
|
||||
Version string `json:"version" db:"version"`
|
||||
Mod []byte `json:"mod" db:"mod"`
|
||||
Zip []byte `json:"zip" db:"zip"`
|
||||
Info []byte `json:"info" db:"info"`
|
||||
}
|
||||
|
||||
// String is not required by pop and may be deleted
|
||||
func (m Module) String() string {
|
||||
jm, _ := json.Marshal(m)
|
||||
return string(jm)
|
||||
}
|
||||
|
||||
// Modules is not required by pop and may be deleted
|
||||
type Modules []Module
|
||||
|
||||
// String is not required by pop and may be deleted
|
||||
func (m Modules) String() string {
|
||||
jm, _ := json.Marshal(m)
|
||||
return string(jm)
|
||||
}
|
||||
|
||||
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
|
||||
// This method is not required and may be deleted.
|
||||
func (m *Module) Validate(tx *pop.Connection) (*validate.Errors, error) {
|
||||
return validate.Validate(
|
||||
&validators.StringIsPresent{Field: m.Module, Name: "Module"},
|
||||
&validators.StringIsPresent{Field: m.Version, Name: "Version"},
|
||||
&validators.BytesArePresent{Field: m.Mod, Name: "Mod"},
|
||||
&validators.BytesArePresent{Field: m.Zip, Name: "Zip"},
|
||||
&validators.BytesArePresent{Field: m.Info, Name: "Info"},
|
||||
), nil
|
||||
}
|
||||
|
||||
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
|
||||
// This method is not required and may be deleted.
|
||||
func (m *Module) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
|
||||
return validate.NewErrors(), nil
|
||||
}
|
||||
|
||||
// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
|
||||
// This method is not required and may be deleted.
|
||||
func (m *Module) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
|
||||
return validate.NewErrors(), nil
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/pop"
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
)
|
||||
|
||||
// ModuleStore represents a rdbms(postgres, mysql, sqlite, cockroachdb) backed storage backend.
|
||||
type ModuleStore struct {
|
||||
conn *pop.Connection
|
||||
connectionName string // settings name from database.yml
|
||||
}
|
||||
|
||||
// NewRDBMSStorage returns a connected RDBMS Module Storage
|
||||
// that satisfies the Storage interface.
|
||||
func NewRDBMSStorage(connectionName string) (*ModuleStore, error) {
|
||||
const op errors.Op = "rdbms.NewRDBMSStorage"
|
||||
|
||||
ms := &ModuleStore{
|
||||
connectionName: connectionName,
|
||||
}
|
||||
err := ms.connect()
|
||||
if err != nil {
|
||||
return nil, errors.E(op, err)
|
||||
}
|
||||
return ms, nil
|
||||
}
|
||||
|
||||
// NewRDBMSStorageWithConn returns a connected RDBMS Module Storage
|
||||
// that satisfies the Storage interface.
|
||||
func NewRDBMSStorageWithConn(connection *pop.Connection) *ModuleStore {
|
||||
ms := &ModuleStore{
|
||||
conn: connection,
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
func (r *ModuleStore) connect() error {
|
||||
c, err := pop.Connect(r.connectionName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.conn = c
|
||||
return nil
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
func (rd *RDBMSTestSuite) TestNewRDBMSStorage() {
|
||||
r := rd.Require()
|
||||
e := "development"
|
||||
getterSaver, err := NewRDBMSStorage(e)
|
||||
r.NoError(err)
|
||||
|
||||
r.NotNil(getterSaver.conn)
|
||||
r.Equal(getterSaver.connectionName, e)
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/gomods/athens/pkg/storage/rdbms/models"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// Save stores a module in rdbms storage.
|
||||
func (r *ModuleStore) Save(ctx context.Context, module, version string, mod []byte, zip io.Reader, info []byte) error {
|
||||
sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Save")
|
||||
defer sp.Finish()
|
||||
zipBytes, err := ioutil.ReadAll(zip)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m := &models.Module{
|
||||
Module: module,
|
||||
Version: version,
|
||||
Mod: mod,
|
||||
Zip: zipBytes,
|
||||
Info: info,
|
||||
}
|
||||
|
||||
return r.conn.Create(m)
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package rdbms
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/suite"
|
||||
"github.com/gomods/athens/pkg/storage"
|
||||
)
|
||||
|
||||
// TestSuite implements TestSuite interface
|
||||
type TestSuite struct {
|
||||
*suite.Model
|
||||
storage storage.Backend
|
||||
}
|
||||
|
||||
// NewTestSuite creates a common test suite
|
||||
func NewTestSuite(model *suite.Model) (storage.TestSuite, error) {
|
||||
conn := model.DB
|
||||
rdbmsStore := NewRDBMSStorageWithConn(conn)
|
||||
|
||||
return &TestSuite{
|
||||
storage: rdbmsStore,
|
||||
Model: model,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Storage retrieves initialized storage backend
|
||||
func (ts *TestSuite) Storage() storage.Backend {
|
||||
return ts.storage
|
||||
}
|
||||
|
||||
// StorageHumanReadableName retrieves readable identifier of the storage
|
||||
func (ts *TestSuite) StorageHumanReadableName() string {
|
||||
return "Rdbms"
|
||||
}
|
||||
|
||||
// Cleanup tears down test
|
||||
func (ts *TestSuite) Cleanup() error {
|
||||
return nil
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/gomods/athens/pkg/storage/mem"
|
||||
"github.com/gomods/athens/pkg/storage/minio"
|
||||
"github.com/gomods/athens/pkg/storage/mongo"
|
||||
"github.com/gomods/athens/pkg/storage/rdbms"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -133,10 +132,6 @@ func getStores(b *testing.B) []storage.TestSuite {
|
||||
require.NoError(b, err, "couldn't create mongo store")
|
||||
stores = append(stores, mongoStore)
|
||||
|
||||
rdbmsStore, err := rdbms.NewTestSuite(model)
|
||||
require.NoError(b, err, "couldn't create mongo store")
|
||||
stores = append(stores, rdbmsStore)
|
||||
|
||||
memStore, err := mem.NewTestSuite(model)
|
||||
require.NoError(b, err)
|
||||
stores = append(stores, memStore)
|
||||
|
||||
+11
-1
@@ -2,7 +2,17 @@
|
||||
|
||||
# test_unit.sh
|
||||
|
||||
source cmd/proxy/.env
|
||||
if [ -z ${ATHENS_MONGO_STORAGE_URL} ]; then
|
||||
export ATHENS_MONGO_STORAGE_URL="mongodb://127.0.0.1:27017"
|
||||
fi
|
||||
|
||||
if [ -z ${GO_ENV} ]; then
|
||||
export GO_ENV="test"
|
||||
fi
|
||||
|
||||
if [ -z ${POP_PATH} ]; then
|
||||
export POP_PATH="${PWD}/cmd/olympus"
|
||||
fi
|
||||
|
||||
# Run the unit tests with the race detector and code coverage enabled
|
||||
set -xeuo pipefail
|
||||
|
||||
Reference in New Issue
Block a user