mark test instances as such

Phillip Davis created

Change summary

forms/snikket_launch.rb |  6 ++++++
lib/snikket.rb          | 12 +++++++++++-
sgx_jmp.rb              |  3 ++-
test/test_snikket.rb    |  8 ++++++++
4 files changed, 27 insertions(+), 2 deletions(-)

Detailed changes

forms/snikket_launch.rb 🔗

@@ -7,3 +7,9 @@ field(
 	label: "Domain for Instance",
 	type: "text-single"
 )
+
+field(
+	var: "test_instance",
+	label: "Is this a test instance?",
+	type: "boolean"
+)

lib/snikket.rb 🔗

@@ -12,7 +12,7 @@ module Snikket
 
 		def self.new(
 			type=nil, to=nil, id=nil,
-			domain: nil, region: nil, av_region: "na"
+			domain: nil, region: nil, test_instance: false, av_region: "na"
 		)
 			stanza = super(type || :set, to, id)
 			node = Nokogiri::XML::Node.new("launch", stanza.document)
@@ -21,6 +21,7 @@ module Snikket
 			stanza.domain = domain if domain
 			stanza.region = region if region
 			stanza.av_region = av_region if av_region
+			stanza.test_instance = test_instance
 			stanza
 		end
 
@@ -51,6 +52,15 @@ module Snikket
 		def query
 			at_xpath("./ns:launch", ns: self.class.registered_ns)
 		end
+
+		def test_instance=(enabled)
+			query.at_xpath("./ns:test-instance", ns: self.class.registered_ns)&.remove
+			return unless enabled
+
+			node = Nokogiri::XML::Node.new("test-instance", document)
+			node.default_namespace = self.class.registered_ns
+			query << node
+		end
 	end
 
 	class Launched < Blather::Stanza::Iq

sgx_jmp.rb 🔗

@@ -955,9 +955,10 @@ Command.new(
 			reply.command << FormTemplate.render("snikket_launch")
 		}.then { |response|
 			domain = response.form.field("domain").value.to_s
+			test_instance = response.field("test_instance")&.value.to_s
 			IQ_MANAGER.write(Snikket::Launch.new(
 				nil, CONFIG[:snikket_hosting_api],
-				domain: domain
+				domain: domain, test_instance: test_instance
 			)).then do |launched|
 				Snikket::CustomerInstance.for(customer, domain, launched)
 			end

test/test_snikket.rb 🔗

@@ -14,6 +14,14 @@ class TestSnikket < Minitest::Test
 			"example.com",
 			launch.query.at_xpath("./ns:domain", ns: NS).content
 		)
+		assert_nil launch.query.at_xpath("./ns:test-instance", ns: NS)
+	end
+
+	def test_launch_test_instance
+		launch = Snikket::Launch.new(
+			domain: "jmp-test-example.com", test_instance: true
+		)
+		refute_nil launch.query.at_xpath("./ns:test-instance", ns: NS)
 	end
 
 	def test_launched