[SCM] ci-tooling packaging branch, master, updated. 81eda080c0042379d745029488c047ddb748db1d
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Mon Jan 5 01:27:24 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=a62ef8d
The following commit has been merged in the master branch:
commit a62ef8d79457e84a866eed71aa908ba087671ade
Author: Harald Sitter <sitter at kde.org>
Date: Mon Jan 5 02:26:19 2015 +0100
add testing for parser and lp
---
Rakefile | 8 +++
test/data/lp/ppa-sources-kate-1.json | 8 +++
test/data/lp/ppa-sources-kate-2.json | 7 +++
test/data/lp/ppa.json | 2 +
test/run_all.rb | 5 ++
test/test-lp.rb | 94 ++++++++++++++++++++++++++++++
test/test-parse.rb | 110 +++++++++++++++++++++++++++++++++++
7 files changed, 234 insertions(+)
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..795ec61
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,8 @@
+require "ci/reporter/rake/test_unit"
+require "rake/testtask"
+
+Rake::TestTask.new do |t|
+ t.test_files = FileList["test/test-*.rb"]
+ t.verbose = false
+end
+task :test => "ci:setup:testunit"
diff --git a/test/data/lp/ppa-sources-kate-1.json b/test/data/lp/ppa-sources-kate-1.json
new file mode 100644
index 0000000..27fcffb
--- /dev/null
+++ b/test/data/lp/ppa-sources-kate-1.json
@@ -0,0 +1,8 @@
+{
+ "total_size": 2,
+ "start": 0,
+ "next_collection_link": "https://api.launchpad.net/devel/%7Ekubuntu-ci/+archive/ubuntu/unstable?source_name=kate\u0026ws.op=getPublishedSources\u0026ws.size=2\u0026memo=2\u0026ws.start=2",
+ "entries": [
+ {"package_creator_link": "https://api.launchpad.net/devel/~kubuntu-ci", "package_signer_link": "https://api.launchpad.net/devel/~neon-builder", "source_package_name": "kate", "removal_comment": null, "sponsor_link": null, "display_name": "kate 4:4.50.0+git20141115.0010+15.04-0ubuntu0 in vivid", "creator_link": null, "source_package_version": "4:4.50.0+git20141115.0010+15.04-0ubuntu0", "date_superseded": "2014-11-16T00:33:06.201878+00:00", "http_etag": "fc4237808d94e7effa7450844630978fdae55f8b-48111addc5186d4e70102b5292d8d9cbce42e3fe", "packageupload_link": "https://api.launchpad.net/devel/ubuntu/vivid/+upload/8227146", "self_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable/+sourcepub/4571865", "distro_series_link": "https://api.launchpad.net/devel/ubuntu/vivid", "component_name": "main", "status": "Superseded", "date_removed": "2014-11-17T02:10:16.560759+00:00", "pocket": "Release", "date_published": "2014-11-15T00:21:37.927456+00:00", "removed_by_link": null, "section_name": "kde", "date_made_pending": "2014-11-16T00:42:20.004356+00:00", "resource_type_link": "https://api.launchpad.net/devel/#source_package_publishing_history", "archive_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable", "package_maintainer_link": "https://api.launchpad.net/devel/~ubuntu-devel-discuss-lists", "date_created": "2014-11-15T00:11:20.132000+00:00", "scheduled_deletion_date": "2014-11-17T00:42:20.004356+00:00"}, {"package_creator_link": "https://api.launchpad.net/devel/~kubuntu-ci", "package_signer_link": "https://api.launchpad.net/devel/~neon-builder", "source_package_name": "kate", "removal_comment": null, "sponsor_link": null, "display_name": "kate 4:4.50.0+git20141115.0006+14.10-0ubuntu0 in utopic", "creator_link": null, "source_package_version": "4:4.50.0+git20141115.0006+14.10-0ubuntu0", "date_superseded": "2014-11-16T00:33:06.201878+00:00", "http_etag": "063b7fc0e70a10286ecfa7a55ce135edea5c480e-a0dc754cbb052b42f9091cbc3ea60ad2eb2ddc70", "packageupload_link": "https://api.launchpad.net/devel/ubuntu/utopic/+upload/8227121", "self_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable/+sourcepub/4571852", "distro_series_link": "https://api.launchpad.net/devel/ubuntu/utopic", "component_name": "main", "status": "Superseded", "date_removed": "2014-11-17T02:10:16.560759+00:00", "pocket": "Release", "date_published": "2014-11-15T00:21:37.927456+00:00", "removed_by_link": null, "section_name": "kde", "date_made_pending": "2014-11-16T00:42:20.004356+00:00", "resource_type_link": "https://api.launchpad.net/devel/#source_package_publishing_history", "archive_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable", "package_maintainer_link": "https://api.launchpad.net/devel/~ubuntu-devel-discuss-lists", "date_created": "2014-11-15T00:08:11.909701+00:00", "scheduled_deletion_date": "2014-11-17T00:42:20.004356+00:00"}
+ ]
+}
\ No newline at end of file
diff --git a/test/data/lp/ppa-sources-kate-2.json b/test/data/lp/ppa-sources-kate-2.json
new file mode 100644
index 0000000..77dbc2e
--- /dev/null
+++ b/test/data/lp/ppa-sources-kate-2.json
@@ -0,0 +1,7 @@
+{
+ "total_size": 2,
+ "start": 2,
+ "entries": [
+ {"package_creator_link": "https://api.launchpad.net/devel/~kubuntu-ci", "package_signer_link": "https://api.launchpad.net/devel/~neon-builder", "source_package_name": "kate", "removal_comment": null, "sponsor_link": null, "display_name": "kate 4:4.50.0+git20141115.0010+15.04-0ubuntu0 in vivid", "creator_link": null, "source_package_version": "4:4.50.0+git20141115.0010+15.04-0ubuntu0", "date_superseded": "2014-11-16T00:33:06.201878+00:00", "http_etag": "fc4237808d94e7effa7450844630978fdae55f8b-48111addc5186d4e70102b5292d8d9cbce42e3fe", "packageupload_link": "https://api.launchpad.net/devel/ubuntu/vivid/+upload/8227146", "self_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable/+sourcepub/4571865", "distro_series_link": "https://api.launchpad.net/devel/ubuntu/vivid", "component_name": "main", "status": "Superseded", "date_removed": "2014-11-17T02:10:16.560759+00:00", "pocket": "Release", "date_published": "2014-11-15T00:21:37.927456+00:00", "removed_by_link": null, "section_name": "kde", "date_made_pending": "2014-11-16T00:42:20.004356+00:00", "resource_type_link": "https://api.launchpad.net/devel/#source_package_publishing_history", "archive_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable", "package_maintainer_link": "https://api.launchpad.net/devel/~ubuntu-devel-discuss-lists", "date_created": "2014-11-15T00:11:20.132000+00:00", "scheduled_deletion_date": "2014-11-17T00:42:20.004356+00:00"}, {"package_creator_link": "https://api.launchpad.net/devel/~kubuntu-ci", "package_signer_link": "https://api.launchpad.net/devel/~neon-builder", "source_package_name": "kate", "removal_comment": null, "sponsor_link": null, "display_name": "kate 4:4.50.0+git20141115.0006+14.10-0ubuntu0 in utopic", "creator_link": null, "source_package_version": "4:4.50.0+git20141115.0006+14.10-0ubuntu0", "date_superseded": "2014-11-16T00:33:06.201878+00:00", "http_etag": "063b7fc0e70a10286ecfa7a55ce135edea5c480e-a0dc754cbb052b42f9091cbc3ea60ad2eb2ddc70", "packageupload_link": "https://api.launchpad.net/devel/ubuntu/utopic/+upload/8227121", "self_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable/+sourcepub/4571852", "distro_series_link": "https://api.launchpad.net/devel/ubuntu/utopic", "component_name": "main", "status": "Superseded", "date_removed": "2014-11-17T02:10:16.560759+00:00", "pocket": "Release", "date_published": "2014-11-15T00:21:37.927456+00:00", "removed_by_link": null, "section_name": "kde", "date_made_pending": "2014-11-16T00:42:20.004356+00:00", "resource_type_link": "https://api.launchpad.net/devel/#source_package_publishing_history", "archive_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable", "package_maintainer_link": "https://api.launchpad.net/devel/~ubuntu-devel-discuss-lists", "date_created": "2014-11-15T00:08:11.909701+00:00", "scheduled_deletion_date": "2014-11-17T00:42:20.004356+00:00"}
+ ]
+}
\ No newline at end of file
diff --git a/test/data/lp/ppa.json b/test/data/lp/ppa.json
new file mode 100644
index 0000000..26b9d08
--- /dev/null
+++ b/test/data/lp/ppa.json
@@ -0,0 +1,2 @@
+{"status": "Active", "dependencies_collection_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable/dependencies", "external_dependencies": null, "displayname": "Kubuntu CI Unstable", "description": "Direct landing PPA - very unstable
DO NOT USE THIS UNLESS YOU KNOW WHAT YOU ARE DOING.
ppa:kubuntu-ci/unstable-daily is much nicer
ppa:kubuntu-ci/unstable-weekly is even nicer than daily", "reference": "~kubuntu-ci/ubuntu/unstable", "distribution_link": "https://api.launchpad.net/devel/ubuntu", "require_virtualized": true, "web_link": "https://launchpad.net/~kubuntu-ci/+archive/ubuntu/unstable", "private": false, "authorized_size": 16384, "http_etag": "\"d9fe2d526b361ffd1f481c2de5eb589881c72b64-34532db1e8291829a85aabb5d5be6b91a6e23967\"", "owner_link": "https://api.launchpad.net/devel/~kubuntu-ci", "relative_build_score": 0, "self_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable", "enabled_restricted_processors_collection_link": "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable/enabled_restricted_processors", "signing_key_fingerprint": "D807A3EA3406394874332063A12B6139432062D1", "resource_type_link": "https://api.launchpad.net/devel/#archive", "suppress_subscription_notifications": false, "name": "unstable"}
+
diff --git a/test/run_all.rb b/test/run_all.rb
new file mode 100644
index 0000000..774f94e
--- /dev/null
+++ b/test/run_all.rb
@@ -0,0 +1,5 @@
+#!/usr/bin/env ruby
+
+require "test/unit"
+
+exit Test::Unit::AutoRunner.run(true)
diff --git a/test/test-lp.rb b/test/test-lp.rb
new file mode 100644
index 0000000..82975cc
--- /dev/null
+++ b/test/test-lp.rb
@@ -0,0 +1,94 @@
+require "test/unit"
+
+require_relative "../lib/lp"
+
+class LaunchpadTest < Test::Unit::TestCase
+ def test_token
+ assert_equal(Launchpad::token, nil)
+ end
+
+ # FIXME: need auth test
+end
+
+class FakeLaunchpad
+ def self.call(env)
+ case env["REQUEST_METHOD"]
+ when "GET"
+ return get(env)
+ end
+ raise "unhandled http method '#{env["REQUEST_METHOD"]}' in FakeLaunchpad"
+ end
+
+private
+ def self.get(env)
+ case env["PATH_INFO"]
+ when "/devel/~kubuntu-ci/+archive/ubuntu/unstable"
+ # FIXME: code dup and query is order sensitive
+ case env["QUERY_STRING"]
+ when ""
+ return ['200',
+ {'Content-Type' => 'application/json'},
+ [json_response("ppa.json")]]
+ when "source_name=kate&ws.op=getPublishedSources"
+ return ['200',
+ {'Content-Type' => 'application/json'},
+ [json_response("ppa-sources-kate-1.json")]]
+ when "memo=2&source_name=kate&ws.op=getPublishedSources&ws.size=2&ws.start=2"
+ return ['200',
+ {'Content-Type' => 'application/json'},
+ [json_response("ppa-sources-kate-2.json")]]
+ end
+ when "/devel/~kubuntu-ci/+archive/ubuntu/unstable/+sourcepub/4571865"
+ case env["QUERY_STRING"]
+ when "ws.op=changelogUrl"
+ return ['200',
+ {'Content-Type' => 'application/json'},
+ ["\"http://foobar\""]]
+ end
+ end
+ raise "unhandled get url '#{env["PATH_INFO"]}?#{env["QUERY_STRING"]}' in FakeLaunchpad"
+ end
+
+ def self.json_response(file_name)
+ return File.open("#{File.dirname(__FILE__)}/data/lp/#{file_name}").read
+ end
+end
+
+class LaunchpadRubberTest < Test::Unit::TestCase
+ def setup
+ # TODO: make mock optional
+ require "webmock/test_unit"
+ require "rack"
+ WebMock.disable_net_connect!(allow_localhost: true)
+ stub_request(:any, /api.launchpad.net/).to_rack(FakeLaunchpad)
+
+ ppa_url = "https://api.launchpad.net/devel/~kubuntu-ci/+archive/ubuntu/unstable"
+ @ppa = Launchpad::Rubber::from_url(ppa_url)
+ assert(@ppa)
+ # Has a bunch of properties]
+ assert_equal(@ppa.status, "Active")
+ assert_equal(@ppa.name, "unstable")
+ assert_equal(@ppa.self_link, ppa_url)
+ end
+
+ # TODO: test from_json
+ # TODO: maybe test get and post directly?
+
+ def test_ppa_source_collection
+ sources = @ppa.getPublishedSources(source_name: "kate")
+ assert_not_nil(sources)
+ # TODO: when run against live this needs to be >=0
+ assert_equal(sources.size, 4)
+ source = sources[0]
+ # Has a bunch of properties
+ assert_not_nil(source)
+ assert_nothing_raised do
+ source.self_link
+ source.pocket
+ source.status
+ end
+ # Can GET a string-only variable. This mustn't make the parser trip.
+ assert_respond_to(source.changelogUrl(), :downcase)
+ puts source.changelogUrl()[0]
+ end
+end
diff --git a/test/test-parse.rb b/test/test-parse.rb
new file mode 100644
index 0000000..a06d7c0
--- /dev/null
+++ b/test/test-parse.rb
@@ -0,0 +1,110 @@
+require "test/unit"
+
+# FIXME: entirely code copied from pangea... figure something out.
+
+class Shebang
+ attr_reader :valid
+ attr_reader :parser
+
+ def initialize(line)
+ @valid = false
+ @parser = nil
+
+ return unless line
+ return unless line.start_with?("#!")
+
+ parts = line.split(" ")
+
+ return unless parts.size >= 1
+ if parts[0].end_with?("/env")
+ return unless parts.size >= 2
+ @parser = parts[1]
+ elsif !parts[0].include?("/") or parts[0].end_with?("/")
+ return # invalid
+ else
+ @parser = parts[0].split("/").pop
+ end
+
+ @valid = true
+ end
+end
+
+class ParseTest < Test::Unit::TestCase
+ def test_shebang
+ s = Shebang.new(nil)
+ assert(!s.valid)
+
+ s = Shebang.new("")
+ assert(!s.valid)
+
+ s = Shebang.new("#!")
+ assert(!s.valid)
+
+ s = Shebang.new("#!/usr/bin/env ruby")
+ assert(s.valid)
+ assert(s.parser == "ruby")
+
+ s = Shebang.new("#!/usr/bin/bash")
+ assert(s.valid)
+ assert(s.parser == "bash")
+
+ s = Shebang.new("#!/bin/sh -xe")
+ assert(s.valid)
+ assert(s.parser == "sh")
+ end
+
+ def test_syntax
+ basedir = File.dirname(File.expand_path(File.dirname(__FILE__)))
+ Dir.chdir(basedir)
+
+ source_dirs = %w[dci lib tests]
+ source_dirs.each do | source_dir |
+ Dir.glob("#{source_dir}/**/*.rb").each do |file|
+ parse_ruby(file)
+ end
+ Dir.glob("#{source_dir}/**/*.sh").each do |file|
+ parse_shell(file)
+ end
+ end
+
+ # Do not recurse the main dir.
+ Dir.glob("*.rb").each do |file|
+ parse_ruby(file)
+ end
+ Dir.glob("*.sh").each do |file|
+ parse_shell(file)
+ end
+ end
+
+private
+ def parse_bash(file)
+ assert(system("bash -n #{file}"))
+ end
+
+ def parse_ruby(file)
+ puts "ruby file: #{file}"
+ assert(system("ruby -c #{file} 1> /dev/null"))
+ end
+
+ def parse_sh(file)
+ assert(system("sh -n #{file}"))
+ end
+
+ def parse_shell(file)
+ puts "shell file: #{file}"
+ shebang = Shebang.new(File.open(file).readline)
+ case shebang.parser
+ when "bash"
+ parse_bash(file)
+ when "sh"
+ parse_sh(file)
+ else
+ if shebang.valid
+ warn " shell type unknown, falling back to bash"
+ else
+ warn " shebang invalid, falling back to bash"
+ end
+ parse_bash(file)
+ end
+ end
+end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list