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

Test new authentication on CI #771

Closed
wants to merge 15 commits into from
Closed
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
12 changes: 7 additions & 5 deletions .github/workflows/dance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# Do not run this job in parallel for any PR change or branch push
# to save some resources.
concurrency:
group: ${{ github.workflow }}-dance-${{ matrix.db }}-${{ matrix.test }}-${{ github.head_ref || github.ref_name }}
group: ${{ github.workflow }}-dance-${{ matrix.db }}-${{ matrix.newauth }}-${{ matrix.test }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
Expand All @@ -48,7 +48,6 @@ jobs:
# - dbaas_core-1
# - dbaas_core-2
# - dbaas_core-3
# - diff
- dotnet-example
- dotnet-example-auth
- dotnet-example-auth-scram-sha-1
Expand All @@ -72,6 +71,9 @@ jobs:
- restheart-auth
- ycsb-workloada
- ycsb-workloadc
newauth:
- false
- true

steps:
- name: Checkout code
Expand All @@ -95,15 +97,15 @@ jobs:
working-directory: tools

- name: Start environment
run: bin/task env-up-detach DB=${{ matrix.db }}
env:
FERRETDB_IMAGE: ghcr.io/ferretdb/ferretdb-dev:main
run: bin/task env-up-detach DB=${{ matrix.db }} NEWAUTH=${{ matrix.newauth }}

- name: Run init
run: bin/task init

- name: Dance!
run: bin/task dance DB=${{ matrix.db }} TEST=${{ matrix.test }} PARALLEL=10
run: bin/task dance DB=${{ matrix.db }} NEWAUTH=${{ matrix.newauth }} TEST=${{ matrix.test }} PARALLEL=10

- name: Collect logs
if: failure()
Expand All @@ -118,7 +120,7 @@ jobs:
if: failure()
uses: actions/upload-artifact@v3
with:
name: compose-logs-${{ matrix.db }}-${{ matrix.test }}
name: compose-logs-${{ matrix.db }}-${{ matrix.newauth }}-${{ matrix.test }}
path: compose-logs.zip
retention-days: 3

Expand Down
15 changes: 7 additions & 8 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
version: "3"

vars:
DB: ""
TEST: ""
PARALLEL: 0

Expand Down Expand Up @@ -42,9 +41,10 @@ tasks:
--build {{.DB}}
- task: init-repl
- task: init-user
preconditions:
- sh: "test {{.DB}}"
msg: "Please set DB variable to one of `postgresql`, `sqlite`, or `mongodb`"
env:
FERRETDB_TEST_ENABLE_NEW_AUTH: '{{.NEWAUTH}}'
requires:
vars: [DB, NEWAUTH]

env-pull:
cmds:
Expand All @@ -69,10 +69,9 @@ tasks:
desc: "Run all integration tests"
dir: tests
cmds:
- go run ../cmd/dance -db={{.DB}} -p={{.PARALLEL}} {{.TEST}}
preconditions:
- sh: "test {{.DB}}"
msg: "Please set DB variable to one of `postgresql`, `sqlite`, or `mongodb`"
- go run ../cmd/dance -db={{.DB}} -newauth={{.NEWAUTH}} -p={{.PARALLEL}} {{.TEST}}
requires:
vars: [DB, NEWAUTH]

lint:
desc: "Run linters"
Expand Down
3 changes: 2 additions & 1 deletion cmd/dance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func logResult(label string, res map[string]string) {

func main() {
dbF := flag.String("db", "", "database to use: postgresql, sqlite, mongodb")
newAuth := flag.Bool("newauth", false, "use new authentication mechanism")
vF := flag.Bool("v", false, "be verbose")
pF := flag.Int("p", 0, "number of tests to run in parallel")
log.SetFlags(0)
Expand Down Expand Up @@ -124,7 +125,7 @@ func main() {
log.Printf("\tDir changed to %s", dir)
}

expectedConfig, err := cfg.ForDB(*dbF)
expectedConfig, err := cfg.ForDB(*dbF, *newAuth)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- FERRETDB_HANDLER=postgresql
- FERRETDB_POSTGRESQL_URL=postgres://user@postgres:5432/dance
- FERRETDB_REPL_SET_NAME=rs0
- FERRETDB_TEST_ENABLE_NEW_AUTH=true
- FERRETDB_TEST_ENABLE_NEW_AUTH=${FERRETDB_TEST_ENABLE_NEW_AUTH:-false}
extra_hosts:
- "host.docker.internal:host-gateway"

Expand All @@ -29,7 +29,7 @@ services:
- FERRETDB_HANDLER=sqlite
- FERRETDB_SQLITE_URL=file:/state/?_pragma=busy_timeout(20000)
- FERRETDB_REPL_SET_NAME=rs0
- FERRETDB_TEST_ENABLE_NEW_AUTH=true
- FERRETDB_TEST_ENABLE_NEW_AUTH=${FERRETDB_TEST_ENABLE_NEW_AUTH:-false}
extra_hosts:
- "host.docker.internal:host-gateway"

Expand Down
43 changes: 30 additions & 13 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ type Config struct {

// Results stores the expected test results for different databases.
type Results struct {
PostgreSQL *TestConfig
SQLite *TestConfig
MongoDB *TestConfig
PostgreSQLOldAuth *TestConfig
PostgreSQLNewAuth *TestConfig
SQLiteOldAuth *TestConfig
SQLiteNewAuth *TestConfig
MongoDB *TestConfig
}

// TestConfig represents the configuration for tests categorized by status and regular expressions.
Expand Down Expand Up @@ -128,29 +130,44 @@ const (
)

// ForDB returns the database-specific test configuration based on the provided dbName.
func (c *Config) ForDB(dbName string) (*TestConfig, error) {
return c.Results.forDB(dbName)
func (c *Config) ForDB(dbName string, newAuth bool) (*TestConfig, error) {
return c.Results.forDB(dbName, newAuth)
}

func (r *Results) forDB(dbName string) (*TestConfig, error) {
switch dbName {
case "postgresql":
if c := r.PostgreSQL; c != nil {
func (r *Results) forDB(dbName string, newAuth bool) (*TestConfig, error) {
key := dbName
if newAuth {
key += "-newauth"
} else {
key += "-oldauth"
}

switch key {
case "postgresql-oldauth":
if c := r.PostgreSQLOldAuth; c != nil {
return c, nil
}
case "postgresql-newauth":
if c := r.PostgreSQLNewAuth; c != nil {
return c, nil
}
case "sqlite-oldauth":
if c := r.SQLiteOldAuth; c != nil {
return c, nil
}
case "sqlite":
if c := r.SQLite; c != nil {
case "sqlite-newauth":
if c := r.SQLiteNewAuth; c != nil {
return c, nil
}
case "mongodb":
if c := r.MongoDB; c != nil {
return c, nil
}
default:
return nil, fmt.Errorf("unknown database %q", dbName)
return nil, fmt.Errorf("unknown database %q for newAuth=%t", dbName, newAuth)
}

return nil, fmt.Errorf("no expected results for %q", dbName)
return nil, fmt.Errorf("no expected results for %q and newAuth=%t", dbName, newAuth)
}

// IndentedOutput returns the output of a test result with indented lines.
Expand Down
36 changes: 25 additions & 11 deletions internal/configload/configload.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ type config struct {
Results struct {
// Includes is a mapping that allows us to merge sequences together,
// which is currently not possible in the YAML spec - https://github.com/yaml/yaml/issues/48
Includes map[string][]string `yaml:"includes"`
PostgreSQL *backend `yaml:"postgresql"`
SQLite *backend `yaml:"sqlite"`
MongoDB *backend `yaml:"mongodb"`
Includes map[string][]string `yaml:"includes"`
PostgreSQLOldAuth *backend `yaml:"postgresql-oldauth"`
PostgreSQLNewAuth *backend `yaml:"postgresql-newauth"`
SQLiteOldAuth *backend `yaml:"sqlite-oldauth"`
SQLiteNewAuth *backend `yaml:"sqlite-newauth"`
MongoDB *backend `yaml:"mongodb"`
} `yaml:"results"`
}

Expand All @@ -59,14 +61,24 @@ func Load(file string) (*ic.Config, error) {
return nil, fmt.Errorf("failed to decode config: %w", err)
}

postgreSQL, err := cfg.Results.PostgreSQL.convert(cfg.Results.Includes)
postgreSQLOldAuth, err := cfg.Results.PostgreSQLOldAuth.convert(cfg.Results.Includes)
if err != nil {
return nil, fmt.Errorf("failed to convert PostgreSQL config: %w", err)
return nil, fmt.Errorf("failed to convert PostgreSQL-oldauth config: %w", err)
}

sqLite, err := cfg.Results.SQLite.convert(cfg.Results.Includes)
postgreSQLNewAuth, err := cfg.Results.PostgreSQLNewAuth.convert(cfg.Results.Includes)
if err != nil {
return nil, fmt.Errorf("failed to convert SQLite config: %w", err)
return nil, fmt.Errorf("failed to convert PostgreSQL-newauth config: %w", err)
}

sqLiteOldAuth, err := cfg.Results.SQLiteOldAuth.convert(cfg.Results.Includes)
if err != nil {
return nil, fmt.Errorf("failed to convert SQLite-oldauth config: %w", err)
}

sqLiteNewAuth, err := cfg.Results.SQLiteNewAuth.convert(cfg.Results.Includes)
if err != nil {
return nil, fmt.Errorf("failed to convert SQLite-newauth config: %w", err)
}

mongoDB, err := cfg.Results.MongoDB.convert(cfg.Results.Includes)
Expand All @@ -79,9 +91,11 @@ func Load(file string) (*ic.Config, error) {
Dir: cfg.Dir,
Args: cfg.Args,
Results: ic.Results{
PostgreSQL: postgreSQL,
SQLite: sqLite,
MongoDB: mongoDB,
PostgreSQLOldAuth: postgreSQLOldAuth,
PostgreSQLNewAuth: postgreSQLNewAuth,
SQLiteOldAuth: sqLiteOldAuth,
SQLiteNewAuth: sqLiteNewAuth,
MongoDB: mongoDB,
},
}, nil
}
Loading