From 163c82cc4302269cc8ca06d50cf113c4865b70ff Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 14:29:51 +0100 Subject: [PATCH 01/13] include virtuoso as a service in CI include the tenforce/virutoso docker container as a service in the github ci.yml however, currently just the service, not yet included in any tests #15 --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b65e2a5..f41226c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,16 @@ jobs: - 3.0 - ruby-head # Eventualy - jruby + services: + virtuoso: + image: tenforce/virtuoso + env: + DBA_PASSWORD: tester + SPARQL_UPDATE: true + DEFAULT_GRAPH: test:graph + ports: + - 8890:8890 + - 1111:1111 steps: - name: Clone repository uses: actions/checkout@v2 From 2a4ed72c4a8899c3b3aae1027a99b3ae953c0771 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 15:25:02 +0100 Subject: [PATCH 02/13] a basic integration test that does a simple query #15 a simple check that the repo is connecting and querying within the Github CI environment --- spec/integration_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/integration_spec.rb diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb new file mode 100644 index 0000000..1dbc830 --- /dev/null +++ b/spec/integration_spec.rb @@ -0,0 +1,32 @@ +$:.unshift "." +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/repository' + +# these tests rely on a Virtuoso instance being available, at port 8890, and will otherwise fail +# the easiest way to do this is with docker ( https://docs.docker.com/get-docker/ ), running the following: +# docker run -p 8890:8890 -p 1111:1111 -e DBA_PASSWORD=tester -e SPARQL_UPDATE=true --name virtuoso-testing -d tenforce/virtuoso +# when finished you can stop with +# docker stop virtuoso-testing + +describe RDF::Virtuoso::Repository do + context('when interating with a virtuoso repository instance') do + let(:uri) {"http://localhost:8890/sparql"} + let(:update_uri) {"http://localhost:8890/sparql-auth"} + let(:repo) {RDF::Virtuoso::Repository.new(uri)} + let(:password) {'tester'} + let(:username) {'dba'} + let(:repo) { + RDF::Virtuoso::Repository.new(uri, + update_uri: update_uri, + username: username, + password: password, + auth_method: 'digest') + } + + it 'should be able to select' do + query = RDF::Virtuoso::Query.select.where([RDF::Resource('http://localhost:8890/sparql'), :p, :o]) + expect(repo.select(query).count).to eql 14 + end + end +end + \ No newline at end of file From 1c48c9a49a629abb76b828885172fa55d178f6c2 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 15:26:52 +0100 Subject: [PATCH 03/13] the default graph is unlikely to be needed #15 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f41226c..a14546b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,8 +31,7 @@ jobs: image: tenforce/virtuoso env: DBA_PASSWORD: tester - SPARQL_UPDATE: true - DEFAULT_GRAPH: test:graph + SPARQL_UPDATE: true ports: - 8890:8890 - 1111:1111 From 385345c35af501344f255c856a6a4a507040fa31 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 15:44:17 +0100 Subject: [PATCH 04/13] wait 3 seconds extra, to give virtuoso service more time after the container starts, it needs just a couple of seconds to initialise. Hopefully 3s is enough to avoid any sporadic errors #15 --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a14546b..f6206fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,10 @@ jobs: ruby-version: ${{ matrix.ruby }} - name: Install dependencies run: bundle install --jobs 4 --retry 3 + - name: Wait to give Virtuoso a little extra time + run: jakejarvis/wait-action@master + with: + time: '3s' - name: Run tests run: bundle exec rspec spec From 240cc25c3cd41d36a89fb75cf3f5336b33c157a4 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 15:45:15 +0100 Subject: [PATCH 05/13] rubocop on integration spec --- spec/integration_spec.rb | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 1dbc830..68f8efc 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,4 +1,4 @@ -$:.unshift "." +$:.unshift '.' require File.join(File.dirname(__FILE__), 'spec_helper') require 'rdf/spec/repository' @@ -9,24 +9,23 @@ # docker stop virtuoso-testing describe RDF::Virtuoso::Repository do - context('when interating with a virtuoso repository instance') do - let(:uri) {"http://localhost:8890/sparql"} - let(:update_uri) {"http://localhost:8890/sparql-auth"} - let(:repo) {RDF::Virtuoso::Repository.new(uri)} - let(:password) {'tester'} - let(:username) {'dba'} - let(:repo) { - RDF::Virtuoso::Repository.new(uri, - update_uri: update_uri, - username: username, - password: password, - auth_method: 'digest') - } + context('when interating with a virtuoso repository instance') do + let(:uri) { 'http://localhost:8890/sparql' } + let(:update_uri) { 'http://localhost:8890/sparql-auth' } + let(:repo) { RDF::Virtuoso::Repository.new(uri) } + let(:password) { 'tester' } + let(:username) { 'dba' } + let(:repo) do + RDF::Virtuoso::Repository.new(uri, + update_uri: update_uri, + username: username, + password: password, + auth_method: 'digest') + end - it 'should be able to select' do - query = RDF::Virtuoso::Query.select.where([RDF::Resource('http://localhost:8890/sparql'), :p, :o]) - expect(repo.select(query).count).to eql 14 - end + it 'should be able to select' do + query = RDF::Virtuoso::Query.select.where([RDF::Resource('http://localhost:8890/sparql'), :p, :o]) + expect(repo.select(query).count).to eql 14 end + end end - \ No newline at end of file From d8b57eab2ee67679f46861a7a2ba2202568c523c Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 15:47:32 +0100 Subject: [PATCH 06/13] uses not run! #15 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6206fe..6f50bf9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: - name: Install dependencies run: bundle install --jobs 4 --retry 3 - name: Wait to give Virtuoso a little extra time - run: jakejarvis/wait-action@master + uses: jakejarvis/wait-action@master with: time: '3s' - name: Run tests From 6209ee9ae3e516b552fccc515d34bbcdafa039d4 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 16:20:06 +0100 Subject: [PATCH 07/13] include it_behaves_like an RDF::Repository --- spec/integration_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 68f8efc..092b042 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -27,5 +27,9 @@ query = RDF::Virtuoso::Query.select.where([RDF::Resource('http://localhost:8890/sparql'), :p, :o]) expect(repo.select(query).count).to eql 14 end + + it_behaves_like "an RDF::Repository" do + let(:repository) {repo} + end end end From f25b49e30b9143a11e7502a30ff407428f6afe21 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 16:53:27 +0100 Subject: [PATCH 08/13] try a different sleep action #15 the previous one gave a warning --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f50bf9..6bda2f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: - name: Install dependencies run: bundle install --jobs 4 --retry 3 - name: Wait to give Virtuoso a little extra time - uses: jakejarvis/wait-action@master + uses: juliangruber/sleep-action@v1 with: time: '3s' - name: Run tests From d389debf56dc17ce2fe05d3b0754f892524fcbed Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 12 Apr 2021 16:54:17 +0100 Subject: [PATCH 09/13] disable the it_behaves_like check for now #15 --- spec/integration_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 092b042..e5fc947 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -28,8 +28,9 @@ expect(repo.select(query).count).to eql 14 end - it_behaves_like "an RDF::Repository" do - let(:repository) {repo} - end + # it_behaves_like "an RDF::Repository" do + # let(:repository) {repo} + # end + end end From 061c2a50785b2bb50b0470df4fa88599fc785822 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Tue, 13 Apr 2021 15:59:53 +0100 Subject: [PATCH 10/13] extend tests to check the connection is working and some cleaning up check with a single select which is unlikely to change, and also include a simple insert #15 --- spec/integration_spec.rb | 45 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index e5fc947..b7a2336 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,4 +1,6 @@ -$:.unshift '.' +# frozen_string_literal: true + +$LOAD_PATH.unshift '.' require File.join(File.dirname(__FILE__), 'spec_helper') require 'rdf/spec/repository' @@ -9,28 +11,43 @@ # docker stop virtuoso-testing describe RDF::Virtuoso::Repository do - context('when interating with a virtuoso repository instance') do + context('when interacting with a virtuoso repository instance') do + subject(:repository) do + described_class.new(uri, + update_uri: update_uri, + username: username, + password: password, + auth_method: 'digest') + end + let(:uri) { 'http://localhost:8890/sparql' } let(:update_uri) { 'http://localhost:8890/sparql-auth' } - let(:repo) { RDF::Virtuoso::Repository.new(uri) } let(:password) { 'tester' } let(:username) { 'dba' } - let(:repo) do - RDF::Virtuoso::Repository.new(uri, - update_uri: update_uri, - username: username, - password: password, - auth_method: 'digest') + let(:graph) { 'http://example.org/' } + + it 'is able to select' do + # check a single triple result which is unlikely to change + + query = RDF::Virtuoso::Query.select.where([RDF::URI('http://localhost:8890/sparql'), + RDF::URI('http://www.w3.org/ns/sparql-service-description#endpoint'), :o]) + + expect(repository.select(query).last.o).to eql RDF::URI('http://localhost:8890/sparql') end - it 'should be able to select' do - query = RDF::Virtuoso::Query.select.where([RDF::Resource('http://localhost:8890/sparql'), :p, :o]) - expect(repo.select(query).count).to eql 14 + it 'is able to insert' do + query = RDF::Virtuoso::Query.insert([RDF::URI('subject:person'), RDF::URI('http://purl.org/dc/terms/title'), + 'The title']).graph(graph) + expect(repository.insert(query)).to eql 'Insert into , 1 (or less) triples -- done' + + # #clean up + query = RDF::Virtuoso::Query.delete([RDF::URI('subject:person'), :p, + :o]).where([RDF::URI('subject:person'), :p, :o]).graph(graph) + repository.delete(query) end # it_behaves_like "an RDF::Repository" do - # let(:repository) {repo} + # let(:repository) {subject} # end - end end From 85288859abc1c3e80c31ae53ab282c1764b9d60a Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Tue, 13 Apr 2021 16:21:19 +0100 Subject: [PATCH 11/13] fixed invoking it_behaves_like but commented out until resolved explicity setting the let(:repository) caused an infinite loop and stack overflow, because the subject is already named it works without #15 --- spec/integration_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index b7a2336..5f86671 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -46,8 +46,8 @@ repository.delete(query) end - # it_behaves_like "an RDF::Repository" do - # let(:repository) {subject} - # end + # commented out until conformance issues are resolved, otherwise there are many errors + # it_behaves_like "an RDF::Repository" + end end From 25157872ca6f5213d13a0985765a5be27b44d9f6 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Tue, 13 Apr 2021 16:33:58 +0100 Subject: [PATCH 12/13] control whether the integration tests are run with an env variable #15 --- .github/workflows/ci.yml | 1 + spec/integration_spec.rb | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bda2f6..6071694 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: runs-on: ubuntu-latest env: CI: true + VIRTUOSO_INTEGRATION_TESTS: true strategy: fail-fast: false matrix: diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 5f86671..50efe6f 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -4,14 +4,19 @@ require File.join(File.dirname(__FILE__), 'spec_helper') require 'rdf/spec/repository' -# these tests rely on a Virtuoso instance being available, at port 8890, and will otherwise fail +# these tests rely on a Virtuoso service being available, at port 8890 # the easiest way to do this is with docker ( https://docs.docker.com/get-docker/ ), running the following: # docker run -p 8890:8890 -p 1111:1111 -e DBA_PASSWORD=tester -e SPARQL_UPDATE=true --name virtuoso-testing -d tenforce/virtuoso # when finished you can stop with # docker stop virtuoso-testing +# +# to avoid the tests being skipped, you will need to set the environment variable VIRTUOSO_INTEGRATION_TESTS, e.g. +# VIRTUOSO_INTEGRATION_TESTS=true bundle exec rspec spec -describe RDF::Virtuoso::Repository do - context('when interacting with a virtuoso repository instance') do +skip = ENV['VIRTUOSO_INTEGRATION_TESTS'] ? false : 'Skipping Integration tests against a running repository, see spec/integration_spec.rb' + +describe RDF::Virtuoso::Repository, skip: skip do + context('when interacting with a virtuoso repository service') do subject(:repository) do described_class.new(uri, update_uri: update_uri, @@ -28,7 +33,6 @@ it 'is able to select' do # check a single triple result which is unlikely to change - query = RDF::Virtuoso::Query.select.where([RDF::URI('http://localhost:8890/sparql'), RDF::URI('http://www.w3.org/ns/sparql-service-description#endpoint'), :o]) @@ -47,7 +51,6 @@ end # commented out until conformance issues are resolved, otherwise there are many errors - # it_behaves_like "an RDF::Repository" - + # it_behaves_like "an RDF::Repository" end end From ec1ad92b6a8a900eb64c8aeb4d40ef5bcfcd00a6 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Thu, 15 Apr 2021 09:33:00 +0100 Subject: [PATCH 13/13] Update spec/integration_spec.rb Co-authored-by: Gregg Kellogg --- spec/integration_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 50efe6f..0867201 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true $LOAD_PATH.unshift '.' -require File.join(File.dirname(__FILE__), 'spec_helper') +require_relative 'spec_helper' require 'rdf/spec/repository' # these tests rely on a Virtuoso service being available, at port 8890