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

fix(specs): clean and fix specs #384

Merged
merged 5 commits into from
Jun 17, 2024
Merged
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
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AWS_REGION="us-east-1"
AWS_KEY="root"
AWS_SECRET="password"
AWS_S3_ENDPOINT="http://minio:9000"
AWS_S3_BUCKET="placeos-drivers-build-service"
62 changes: 53 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version: "3.7"
x-deployment-env: &deployment-env
ENV: ${ENV:-development}
SG_ENV: ${SG_ENV:-development}
TZ: $TZ

x-elastic-client-env: &elastic-client-env
ELASTIC_HOST: ${ELASTIC_HOST:-elastic}
Expand All @@ -26,6 +25,18 @@ x-postgresdb-client-env: &postgresdb-client-env
x-search-ingest-client-env: &search-ingest-client-env
SEARCH_INGEST_URI: ${SEARCH_INGEST_URI:-http://search-ingest:3000}

x-s3-client-env: &s3-client-env
AWS_REGION: ${AWS_REGION:-"us-east-1"}
AWS_KEY: ${AWS_KEY:-"root"}
AWS_SECRET: ${AWS_SECRET:-"password"}
AWS_S3_ENDPOINT: ${AWS_S3_ENDPOINT:-"http://minio:9000"}
AWS_S3_BUCKET: ${AWS_S3_BUCKET:-"placeos-drivers-build-service"}

x-build-api-env: &build-api-env
BUILD_API_HOST: ${BUILD_API_HOST:-build_service}
BUILD_API_PORT: ${BUILD_API_PORT:-3000}


services:
test: # Rest API
image: placeos/service-spec-runner:${CRYSTAL_VERSION:-latest}
Expand Down Expand Up @@ -73,13 +84,6 @@ services:
ports:
- 9200:9200

elasticvue:
image: cars10/elasticvue:latest
restart: always
hostname: elasticvue
ports:
- 8080:8080

redis:
image: eqalpha/keydb
restart: always
Expand Down Expand Up @@ -147,7 +151,6 @@ services:
*redis-client-env,
]
COAUTH_NO_SSL: "true"
TZ: $TZ
PLACE_URI: https://${PLACE_DOMAIN:-localhost:8443}

core: # Module coordinator
Expand All @@ -158,6 +161,7 @@ services:
- redis
- migrator
- postgres
- build_service
ulimits:
nofile: 40000
core:
Expand All @@ -172,5 +176,45 @@ services:
*postgresdb-client-env,
# Environment
*deployment-env,
# Build API
*build-api-env,
]

build_service:
image: placeos/build_service:nightly
restart: always
hostname: build_service
depends_on:
- minio
- testbucket
environment:
<<: *s3-client-env

minio:
image: minio/minio:latest
volumes:
- s3:/data
ports:
- 9000:9000
- 9090:9090
environment:
<< : *s3-client-env
MINIO_ROOT_USER: $AWS_KEY
MINIO_ROOT_PASSWORD: $AWS_SECRET
command: server /data --console-address ":9090"

testbucket:
image: minio/mc:latest
depends_on:
- minio
environment:
<< : *s3-client-env
entrypoint: >
sh -c '
sleep 3 &&
mc config host add s3 $AWS_S3_ENDPOINT $AWS_KEY $AWS_SECRET &&
mc mb -p s3/$AWS_S3_BUCKET &&
exit 0
'
volumes:
s3:
15 changes: 0 additions & 15 deletions spec/controllers/drivers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@ module PlaceOS::Api
result.body.should contain "role must not change"
end
end

it "POST /:id/recompile" do
driver = get_driver
path = File.join(Drivers.base_route, "#{driver.id.not_nil!}/recompile")
response = client.post(
path: path,
headers: Spec::Authentication.headers,
)

response.success?.should be_true
unless response.status_code == 208 || response.body.empty?
updated = Model::Driver.from_trusted_json(response.body)
updated.commit.starts_with?("RECOMPILE").should be_false
end
end
end

describe "scopes" do
Expand Down
3 changes: 3 additions & 0 deletions spec/controllers/edges_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module PlaceOS::Api
end

describe "CRUD operations", tags: "crud" do
::Spec.before_each do
PlaceOS::Model::Edge.clear
end
Spec.test_crd(Model::Edge, Edges)

describe "create" do
Expand Down
8 changes: 7 additions & 1 deletion spec/controllers/systems_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ require "http/web_socket"
require "../helper"

module PlaceOS::Api
::Spec.before_each do
PlaceOS::Model::Module.clear
PlaceOS::Model::Driver.clear
PlaceOS::Model::ControlSystem.clear
end

def self.spec_add_module(system, mod, headers)
mod_id = mod.id.as(String)
path = Systems::NAMESPACE.first + "#{system.id}/module/#{mod_id}"
Expand Down Expand Up @@ -180,7 +186,7 @@ module PlaceOS::Api
sys.modules = [module_id]
end
systems.each &.save!

sleep 1
expected_ids = expected_systems.compact_map(&.id)
total_ids = expected_ids.size

Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helpers/core_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def setup_system(repository_folder_name = "private-drivers")
driver.repository = repository
driver.save!

control_system = PlaceOS::Model::Generator.control_system.save!

mod = PlaceOS::Model::Generator.module(driver: driver)
mod.running = true
mod.save!

control_system = PlaceOS::Model::Generator.control_system.save!

mod.control_system = control_system

control_system.modules = [mod.id.as(String)]
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helpers/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module PlaceOS::Api::Spec
name = random_name
doc.name = name
doc.save!
sleep 1

refresh_elastic({{ klass }}.table_name)

Expand Down
1 change: 1 addition & 0 deletions src/placeos-rest-api/controllers/asset_types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module PlaceOS::Api
as: {String, Int64}
).each { |(id, count)| counts[id] = count }
end

# ameba:disable Style/VerboseBlock
results.each { |type| type.asset_count = counts[type.id]? || 0_i64 }
counts
Expand Down
4 changes: 2 additions & 2 deletions src/placeos-rest-api/controllers/modules.cr
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ module PlaceOS::Api
query = %({#{stream}="core"} | logfmt | source = "#{current_module.id}" | level = "[E]")
results = client.query_range(query, 20, error_timestamp - 1.hour, error_timestamp, Loki::Direction::Backward)
entries = Array(String).new
results.response_data.result.as(Loki::Model::Streams).each do |log_stream|
log_stream.entries.each { |entry| entries << (entry.line.try &.gsub("+ ", "") || "\n") }
results.response_data.result.as(Loki::Model::Streams).each do |res_stream|
res_stream.entries.each { |entry| entries << (entry.line.try &.gsub("+ ", "") || "\n") }
end

entries
Expand Down
Loading