Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/actions/go/pre-merge/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ runs:
if: inputs.task == 'e2e'
env:
IGGY_TCP_ADDRESS: 127.0.0.1:8090
IGGY_ROOT_USERNAME: iggy
IGGY_ROOT_PASSWORD: iggy
run: |
echo "🧪 Running Go e2e tests..."

Expand Down
10 changes: 4 additions & 6 deletions .github/actions/php/pre-merge/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,9 @@ runs:
shell: bash
working-directory: foreign/php
env:
IGGY_HOST: 127.0.0.1
IGGY_PORT: 8090
IGGY_USERNAME: iggy
IGGY_PASSWORD: iggy
IGGY_TCP_ADDRESS: 127.0.0.1:8090
IGGY_ROOT_USERNAME: iggy
IGGY_ROOT_PASSWORD: iggy
run: |
mkdir -p ../../reports
./scripts/test.sh --log-junit ../../reports/php-junit.xml
Expand Down Expand Up @@ -194,8 +193,7 @@ runs:
shell: bash
working-directory: foreign/php
env:
IGGY_HOST: 127.0.0.1
IGGY_PORT: 8090
IGGY_TCP_ADDRESS: 127.0.0.1:8090
IGGY_TLS_CONNECTION_STRING: iggy+tcp://iggy:iggy@127.0.0.1:8090?tls=true&tls_domain=localhost&tls_ca_file=${{ github.workspace }}/core/certs/iggy_ca_cert.pem
IGGY_TLS_PLAINTEXT_ADDRESS: 127.0.0.1:8090
run: ./scripts/test.sh --log-junit ../../reports/php-tls-junit.xml tests/TlsTest.php
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/coverage-baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ jobs:
go test -v -race -coverprofile=../../reports/go-coverage-unit.out ./...

- name: Run BDD tests with coverage
env:
IGGY_TCP_ADDRESS: 127.0.0.1:8090
IGGY_ROOT_USERNAME: iggy
IGGY_ROOT_PASSWORD: iggy
run: |
cd bdd/go
mkdir -p ../../reports
Expand Down
17 changes: 10 additions & 7 deletions bdd/cpp/features/step_definitions/background_steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@
#include <cucumber-cpp/autodetect.hpp>

#include <cstdlib>
#include <stdexcept>
#include <string>

#include "world.hpp"

namespace {
std::string env_or(const char *name, const std::string &fallback) {
std::string required_env(const char *name) {
const char *value = std::getenv(name);
return value != nullptr ? std::string(value) : fallback;
if (value == nullptr || *value == '\0') {
throw std::runtime_error(std::string(name) +
" must be set; run the suite via scripts/run-bdd-tests.sh");
}
return std::string(value);
}
} // namespace

GIVEN("^I have a running Iggy server$") {
cucumber::ScenarioScope<bdd::GlobalContext> context;

// Empty address makes the SDK fall back to its default TCP endpoint; in CI the address
// is supplied via IGGY_TCP_ADDRESS (e.g. iggy-server:8090).
const std::string address = env_or("IGGY_TCP_ADDRESS", "");
const std::string address = required_env("IGGY_TCP_ADDRESS");
iggy::ffi::Client *client = iggy::ffi::new_connection(address);
ASSERT_NE(client, nullptr);
context->client = client;
Expand All @@ -54,7 +57,7 @@ GIVEN("^I am authenticated as the root user$") {
cucumber::ScenarioScope<bdd::GlobalContext> context;
ASSERT_NE(context->client, nullptr);

const std::string username = env_or("IGGY_ROOT_USERNAME", "iggy");
const std::string password = env_or("IGGY_ROOT_PASSWORD", "iggy");
const std::string username = required_env("IGGY_ROOT_USERNAME");
const std::string password = required_env("IGGY_ROOT_PASSWORD");
context->client->login_user(username, password);
}
3 changes: 3 additions & 0 deletions bdd/docker-compose.server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ services:
python-bdd:
<<: *server-bdd-deps

php-bdd:
<<: *server-bdd-deps

go-bdd:
<<: *server-bdd-deps

Expand Down
9 changes: 2 additions & 7 deletions bdd/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,9 @@ services:
build:
context: ..
dockerfile: bdd/php/Dockerfile
depends_on:
iggy-server:
condition: service_healthy
environment:
- IGGY_HOST=iggy-server
- IGGY_PORT=8090
- IGGY_USERNAME=iggy
- IGGY_PASSWORD=iggy
- IGGY_ROOT_USERNAME=iggy
- IGGY_ROOT_PASSWORD=iggy
- BDD_FEATURE=${BDD_FEATURE:-all}
volumes:
- ./scenarios/basic_messaging.feature:/app/features/basic_messaging.feature
Expand Down
10 changes: 4 additions & 6 deletions bdd/go/tests/basic_messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"context"
"errors"
"fmt"
"os"

"github.com/apache/iggy/bdd/go/tests/env"
"github.com/apache/iggy/foreign/go/client"
"github.com/apache/iggy/foreign/go/client/tcp"
iggcon "github.com/apache/iggy/foreign/go/contracts"
Expand Down Expand Up @@ -52,10 +52,7 @@ type basicMessagingSteps struct{}

func (s basicMessagingSteps) givenRunningServer(ctx context.Context) error {
c := getBasicMessagingCtx(ctx)
addr := os.Getenv("IGGY_TCP_ADDRESS")
if addr == "" {
addr = "127.0.0.1:8090"
}
addr := env.ServerAddress()
c.serverAddr = &addr
return nil
}
Expand All @@ -80,7 +77,8 @@ func (s basicMessagingSteps) givenAuthenticationAsRoot(ctx context.Context) erro
return fmt.Errorf("error pinging client: %w", err)
}

if _, err = cli.LoginUser(ctx, "iggy", "iggy"); err != nil {
username, password := env.RootCredentials()
if _, err = cli.LoginUser(ctx, username, password); err != nil {
return fmt.Errorf("error logging in: %v", err)
}

Expand Down
55 changes: 55 additions & 0 deletions bdd/go/tests/env/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// Package env reads the endpoints and credentials the BDD suites run
// against. A default here would turn a dropped compose variable into a run
// against whatever happens to listen on the fallback address, so a missing
// value aborts the suite instead.
package env

import (
"fmt"
"os"
)

func required(name string) string {
value, ok := os.LookupEnv(name)
if !ok || value == "" {
panic(fmt.Sprintf("%s must be set; run the suite via scripts/run-bdd-tests.sh", name))
}
return value
}

// ServerAddress returns the address of the single-node server.
func ServerAddress() string {
return required("IGGY_TCP_ADDRESS")
}

// LeaderAddress returns the address of the cluster leader.
func LeaderAddress() string {
return required("IGGY_TCP_ADDRESS_LEADER")
}

// FollowerAddress returns the address of the cluster follower.
func FollowerAddress() string {
return required("IGGY_TCP_ADDRESS_FOLLOWER")
}

// RootCredentials returns the root username and password.
func RootCredentials() (string, string) {
return required("IGGY_ROOT_USERNAME"), required("IGGY_ROOT_PASSWORD")
}
26 changes: 7 additions & 19 deletions bdd/go/tests/leader_redirection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,18 @@ import (
"errors"
"fmt"
"net"
"os"
"regexp"
"strconv"
"strings"
"time"

"github.com/apache/iggy/bdd/go/tests/env"
"github.com/apache/iggy/foreign/go/client"
"github.com/apache/iggy/foreign/go/client/tcp"
iggcon "github.com/apache/iggy/foreign/go/contracts"
ierror "github.com/apache/iggy/foreign/go/errors"
"github.com/cucumber/godog"
)

const defaultRootUsername = "iggy"
const defaultRootPassword = "iggy"

type leaderCtxKey struct{}
type leaderCtx struct {
Clients map[string]iggcon.Client
Expand Down Expand Up @@ -90,25 +86,16 @@ func resolveServerAddress(role string, port uint16) string {

switch {
case role == "leader" && port == 8091:
if addr, ok := os.LookupEnv("IGGY_TCP_ADDRESS_LEADER"); ok {
return addr
}
return "iggy-leader:8091"
return env.LeaderAddress()

case role == "follower" && port == 8092:
if addr, ok := os.LookupEnv("IGGY_TCP_ADDRESS_FOLLOWER"); ok {
return addr
}
return "iggy-follower:8092"
return env.FollowerAddress()

case port == 8090:
if addr, ok := os.LookupEnv("IGGY_TCP_ADDRESS"); ok {
return addr
}
return "iggy-server:8090"
return env.ServerAddress()

default:
return "iggy-server:" + strconv.Itoa(int(port))
panic(fmt.Sprintf("no address mapping for role %q on port %d", role, port))
}
}

Expand Down Expand Up @@ -323,12 +310,13 @@ func (s leaderSteps) whenAuthenticateRoot(ctx context.Context) error {
names = []string{"main"}
}

username, password := env.RootCredentials()
for _, name := range names {
cli, ok := c.Clients[name]
if !ok {
return fmt.Errorf("client %s should be created", name)
}
if _, err := cli.LoginUser(ctx, defaultRootUsername, defaultRootPassword); err != nil {
if _, err := cli.LoginUser(ctx, username, password); err != nil {
return err
}
// Small delay between multiple authentications to avoid race conditions
Expand Down
11 changes: 4 additions & 7 deletions bdd/go/tests/raw_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"context"
"errors"
"fmt"
"os"

"github.com/apache/iggy/bdd/go/tests/env"
"github.com/apache/iggy/foreign/go/client"
"github.com/apache/iggy/foreign/go/client/tcp"
iggcon "github.com/apache/iggy/foreign/go/contracts"
Expand All @@ -46,11 +46,7 @@ func getRawCommandCtx(ctx context.Context) *rawCommandCtx {
type rawCommandSteps struct{}

func (rawCommandSteps) givenRunningServer(ctx context.Context) error {
address := os.Getenv("IGGY_TCP_ADDRESS")
if address == "" {
address = "127.0.0.1:8090"
}
getRawCommandCtx(ctx).serverAddr = address
getRawCommandCtx(ctx).serverAddr = env.ServerAddress()
return nil
}

Expand All @@ -63,7 +59,8 @@ func (rawCommandSteps) givenAuthenticationAsRoot(ctx context.Context) error {
if err = iggyClient.Connect(ctx); err != nil {
return fmt.Errorf("connect client: %w", err)
}
if _, err = iggyClient.LoginUser(ctx, "iggy", "iggy"); err != nil {
username, password := env.RootCredentials()
if _, err = iggyClient.LoginUser(ctx, username, password); err != nil {
return fmt.Errorf("authenticate client: %w", err)
}
state.client = iggyClient
Expand Down
7 changes: 5 additions & 2 deletions bdd/go/tests/tcp_test/session_feature_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ package tcp_test
import (
"context"

"github.com/apache/iggy/bdd/go/tests/env"
iggcon "github.com/apache/iggy/foreign/go/contracts"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)

var _ = ginkgo.Describe("LOGIN FEATURE:", func() {
rootUsername, rootPassword := env.RootCredentials()

ginkgo.When("user is already logged in", func() {
ginkgo.Context("and tries to log with correct data", func() {
client := createAuthorizedConnection()
user, err := client.LoginUser(context.Background(), "iggy", "iggy")
user, err := client.LoginUser(context.Background(), rootUsername, rootPassword)

itShouldNotReturnError(err)
itShouldReturnUserId(user, 0)
Expand All @@ -47,7 +50,7 @@ var _ = ginkgo.Describe("LOGIN FEATURE:", func() {
ginkgo.When("user is not logged in", func() {
ginkgo.Context("and tries to log with correct data", func() {
client := createClient()
user, err := client.LoginUser(context.Background(), "iggy", "iggy")
user, err := client.LoginUser(context.Background(), rootUsername, rootPassword)

itShouldNotReturnError(err)
itShouldReturnUserId(user, 0)
Expand Down
11 changes: 4 additions & 7 deletions bdd/go/tests/tcp_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ package tcp_test
import (
"context"
"math/rand"
"os"
"strings"
"time"

"github.com/apache/iggy/bdd/go/tests/env"
"github.com/apache/iggy/foreign/go/client"
iggcon "github.com/apache/iggy/foreign/go/contracts"

Expand All @@ -32,21 +32,18 @@ import (

func createAuthorizedConnection() iggcon.Client {
cli := createClient()
_, err := cli.LoginUser(context.Background(), "iggy", "iggy")
username, password := env.RootCredentials()
_, err := cli.LoginUser(context.Background(), username, password)
if err != nil {
panic(err)
}
return cli
}

func createClient() iggcon.Client {
addr := os.Getenv("IGGY_TCP_ADDRESS")
if addr == "" {
addr = "127.0.0.1:8090"
}
cli, err := client.NewIggyClient(
client.WithTcp(
tcp.WithServerAddress(addr),
tcp.WithServerAddress(env.ServerAddress()),
),
)
if err != nil {
Expand Down
Loading
Loading