Skip to content

Commit

Permalink
travis out, github actions in
Browse files Browse the repository at this point in the history
  • Loading branch information
c29m committed Dec 13, 2020
1 parent 7dbc13b commit 75dfe3b
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 97 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby

on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]

jobs:
test:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby: ["ruby-2.1", "ruby-2.2", "ruby-2.3", "ruby-2.4", "ruby-2.5", "ruby-2.6", "ruby-2.7", "ruby-3.0"]

steps:
- uses: actions/checkout@v2
- name: Run docker-compose
run: docker-compose -f docker-compose.yml -f docker-compose-github.yml -f docker-compose-${{matrix.ruby}}.yml run netsnmp
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--color
--require spec_helper
--format documentation
--format progress
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ ruby RUBY_VERSION

gemspec

gem "rake", "~> 12.3"

gem "coveralls", require: false
gem "rspec", "~> 3.5"

group :development do
gem "pry"
end

gem "celluloid-io", "~> 0.17"
gem "nio4r", "~> 1.2" if RUBY_VERSION < "2.2"

platforms :mri do
Expand Down
7 changes: 7 additions & 0 deletions docker-compose-github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
netsnmp:
environment:
- BUNDLE_PATH=/usr/local/bundle
volumes:
- "/usr/local/bundle:/usr/local/bundle"
5 changes: 5 additions & 0 deletions docker-compose-ruby-2.1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.1-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-2.2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.2-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-2.3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.3-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-2.4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.4-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-2.5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.5-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-2.6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.6-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-2.7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:2.7-alpine

5 changes: 5 additions & 0 deletions docker-compose-ruby-3.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'
services:
netsnmp:
image: ruby:3.0-rc-alpine

15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
version: '3'
services:
netsnmp:
environment:
- SNMP_HOST=snmp-server-emulator
- SNMP_PORT=1161
- CI=1
- BUNDLE_SILENCE_ROOT_WARNING=1
- BUNDLE_JOBS=10
image: ruby:alpine
depends_on:
- snmp-server-emulator
volumes:
- ./:/home
entrypoint:
/home/spec/support/specs.sh

snmp-server-emulator:
image: honeyryderchuck/snmp-server-emulator:latest
ports:
Expand Down
10 changes: 2 additions & 8 deletions netsnmp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ Gem::Specification.new do |gem|
gem.metadata["allowed_push_host"] = "https://rubygems.org/"

# Manifest
gem.files = `git ls-files`.split("\n") - Dir["tmp/**/*"]
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
gem.files = Dir["LICENSE.txt", "README.md", "AUTHORS", "lib/**/*.rb"]
gem.test_files = Dir["spec/**/*.rb"]
gem.require_paths = ["lib"]

gem.add_development_dependency "rake", ["~> 10.1", ">= 10.1.0"]
gem.add_development_dependency "rspec", ["~> 3.5", ">= 3.5.0"]

gem.add_development_dependency "celluloid-io", ["~> 0.17", ">= 0.17.2"]
end
4 changes: 2 additions & 2 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
require_relative "support/request_examples"

RSpec.describe NETSNMP::Client do
let(:host) { "localhost" }
let(:host) { SNMPHOST }

let(:device_options) do
{
peername: "localhost",
peername: SNMPHOST,
port: SNMPPORT
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/handlers/celluloid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
around(:each) do |example|
within_io_actor { example.run }
end
let(:proxy) { CelluloidHelpers::Proxy.new("localhost", SNMPPORT) }
let(:proxy) { CelluloidHelpers::Proxy.new(SNMPHOST, SNMPPORT) }
after(:each) { proxy.close }

it_behaves_like "an snmp client" do
Expand Down
2 changes: 1 addition & 1 deletion spec/session_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe NETSNMP::Session do
let(:host) { "localhost" }
let(:host) { SNMPHOST }
let(:options) do
{
version: "2c",
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

require "netsnmp"

SNMPPORT = (ENV["SNMP_PORT"] || 1161).to_i
SNMPPORT = ENV.fetch("SNMP_PORT", 1161).to_i
SNMPHOST = ENV.fetch("SNMP_HOST", "localhost")

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
Expand Down
4 changes: 2 additions & 2 deletions spec/support/request_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
RSpec.shared_examples "an snmp client" do
let(:device_options) do
{
host: "localhost",
host: SNMPHOST,
port: SNMPPORT
}
end
let(:protocol_options) { {} }
let(:extra_options) { {} }
let(:options) { protocol_options.merge(device_options).merge(extra_options) }

subject { described_class.new(options) }
subject { described_class.new(**options) }

describe "#get" do
let(:value) { subject.get(oid: get_oid) }
Expand Down
54 changes: 5 additions & 49 deletions spec/support/specs.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
#!/usr/bin/env bash
#!/bin/sh

function start {
docker pull honeyryderchuck/snmp-server-emulator:latest
docker run -d -p :1161/udp --name test-snmp -v $(pwd)/spec/support/snmpsim:/home/snmp_server/.snmpsim honeyryderchuck/snmp-server-emulator \
--v3-engine-id=000000000000000000000002 \
--agent-udpv4-endpoint=0.0.0.0:1161 --agent-udpv6-endpoint='[::0]:1161' \
--v3-user=simulator --v3-auth-key=auctoritas --v3-priv-key=privatus \
--v3-user=authmd5 --v3-auth-key=maplesyrup --v3-auth-proto=MD5 --v3-priv-proto=NONE \
--v3-user=authsha --v3-auth-key=maplesyrup --v3-auth-proto=SHA --v3-priv-proto=NONE \
--v3-user=authprivshaaes --v3-auth-key=maplesyrup --v3-auth-proto=SHA \
--v3-priv-key=maplesyrup --v3-priv-proto=AES \
--v3-user=authprivmd5aes --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
--v3-priv-key=maplesyrup --v3-priv-proto=AES \
--v3-user=authprivshades --v3-auth-key=maplesyrup --v3-auth-proto=SHA \
--v3-priv-key=maplesyrup --v3-priv-proto=DES \
--v3-user=authprivmd5des --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
--v3-priv-key=maplesyrup --v3-priv-proto=DES \
--v3-user=unsafe --v3-auth-proto=NONE --v3-priv-proto=NONE
apk --update add g++ make git

}

function run {
sleep 20 # give some time for the simulator to boot

port="$(docker port test-snmp 1161/udp)"
export SNMP_PORT=$(echo $port | cut -d':' -f2)

bundle exec rake spec:ci
}

function finish {
docker stop test-snmp
docker rm test-snmp
}

trap finish EXIT

case "$1" in
start)
start
docker logs -f test-snmp
;;
run)
start
run
;;
*)
echo $"Usage: $0 {start|run}"
exit 1
esac
cd /home
bundle install --quiet
bundle exec rake spec:ci
6 changes: 3 additions & 3 deletions spec/v3_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
priv_protocol: :des, security_level: :auth_priv }
end
it "generates the security parameters handler" do
sess = described_class.new(security_options.merge(host: "localhost", port: SNMPPORT))
sess = described_class.new(**security_options.merge(host: SNMPHOST, port: SNMPPORT))
# not generated yet
expect(sess.instance_variable_get(:@security_parameters)).to be_a(NETSNMP::SecurityParameters)
end

it "allows to pass a custom one" do
sec_params = NETSNMP::SecurityParameters.new(security_options)
sess = described_class.new(host: "localhost", port: SNMPPORT, security_parameters: sec_params)
sess = described_class.new(host: SNMPHOST, port: SNMPPORT, security_parameters: sec_params)
# not generated yet
expect(sess.instance_variable_get(:@security_parameters)).to be(sec_params)
end

it "fails if the pass object doesn't follow the expected api" do
expect { described_class.new(host: "localhost", port: SNMPPORT, security_parameters: double) }.to raise_error(NETSNMP::Error)
expect { described_class.new(host: SNMPHOST, port: SNMPPORT, security_parameters: double) }.to raise_error(NETSNMP::Error)
end
end

0 comments on commit 75dfe3b

Please sign in to comment.