public void TestProvisionUpdateServer() { var server = new Server( new OperatingSystem(name: "Fedora 32 x64"), Plan, Region, label: "my new server" ); using var requests = new MockVultrRequests( new HttpHandler( "/os/list", Resources.VultrOSList), new HttpHandler("/regions/list?availability=yes", Resources.VultrRegionsList), new HttpHandler("/plans/list?type=all", Resources.VultrPlansList), new HttpHandler("/sshkey/list", "{}"), new HttpHandler( "/server/list", Resources.VultrServerList), new HttpHandler( "/server/destroy", "SUBID=576965", ""), new HttpHandler("/server/create", "DCID=1&VPSPLANID=201&OSID=389&enable_private_network=no&label=my+new+server¬ify_activate=no&FIREWALLGROUPID=0", "{\"SUBID\": \"1312965\"}") ); new VultrServerProvisioner(requests.Client).Provision(server); requests.AssertAllCalledOnce(); }
public void AddRuleToFirewall() { var firewall = new Firewall("my http firewall", new FirewallRule( IpType.V4, Protocol.TCP, "8080", "192.0.0.1", 20), new FirewallRule( IpType.V4, Protocol.TCP, "80", "cloudflare") ); using var requests = new MockVultrRequests( new HttpHandler( "/firewall/group_list", Resources.VultrFirewallGroupList), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4", "{}"), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v6", "{}"), new HttpHandler( "/firewall/rule_create", new ValidateRequestHandler( "FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4&" + "protocol=tcp&subnet=192.0.0.1&subnet_size=20&port=8080", "{\"rulenumber\": 2}"), new ValidateRequestHandler( "FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4&" + "protocol=tcp&subnet=0.0.0.0&subnet_size=0&port=80&" + "source=cloudflare", "{\"rulenumber\": 3}"))); new VultrFirewallProvisioner(requests.Client).Provision(firewall); requests.AssertAllCalledOnce(); }
public void TestDestroyFirewallDryrun() { var firewall = new Firewall("my http firewall", new FirewallRule( IpType.V4, Protocol.TCP, "8080", "192.0.0.1", 20) ); using var requests = new MockVultrRequests( new HttpHandler( "/firewall/group_list", Resources.VultrFirewallGroupList), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4", @" { ""1"": { ""rulenumber"": 1, ""action"": ""accept"", ""protocol"": ""tcp"", ""port"": ""8080"", ""subnet"": ""192.0.0.1"", ""subnet_size"": 20, ""source"": """", ""notes"": """" } }"), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v6", "{}")); new VultrFirewallDestroyer(requests.Client).Destroy(firewall, true); requests.AssertAllCalledOnce(); }
public void TestMockGetInfo() { using var requests = new MockVultrRequests( new HttpHandler( "/account/info", Resources.AccountInfo)); var account = requests.Client.Account.GetInfo(); Assert.Equal("-5519.11", account.Account.balance); requests.AssertAllCalledOnce(); }
public void TestDestroyScriptDryrun() { var script = new Script( "hello-boot", ScriptType.Boot, "this is my script"); using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/list", Resources.VultrStartupScripts) ); new VultrScriptDestroyer(requests.Client).Destroy(script, true); requests.AssertAllCalledOnce(); }
public void TestProvisionScriptDryrun() { var script = new Script( "myscript", ScriptType.Boot, "this is my script"); using var requests = new MockVultrRequests( new HttpHandler("/startupscript/list") ); new VultrScriptProvisioner(requests.Client).Provision(script, true); requests.AssertAllCalledOnce(); }
public void UpdateExistingRule() { var firewall = new Firewall("my http firewall", new FirewallRule( IpType.V4, Protocol.TCP, "8080", "192.0.0.1", 20), new FirewallRule( IpType.V4, Protocol.TCP, "80", "cloudflare") ); using var requests = new MockVultrRequests( new HttpHandler( "/firewall/group_list", Resources.VultrFirewallGroupList), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4", @" { ""1"": { ""rulenumber"": 1, ""action"": ""accept"", ""protocol"": ""tcp"", ""port"": ""8081"", ""subnet"": ""192.0.0.1"", ""subnet_size"": 20, ""source"": """", ""notes"": """" }, ""2"": { ""rulenumber"": 1, ""action"": ""accept"", ""protocol"": ""tcp"", ""port"": ""80"", ""subnet"": ""0.0.0.0"", ""subnet_size"": 0, ""source"": ""cloudflare"", ""notes"": """" } }"), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v6", "{}"), new HttpHandler( "/firewall/rule_delete", "FIREWALLGROUPID=1234abcd&rulenumber=1", ""), new HttpHandler( "/firewall/rule_create", "FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4&" + "protocol=tcp&subnet=192.0.0.1&subnet_size=20&port=8080", "{\"rulenumber\": 2}")); new VultrFirewallProvisioner(requests.Client).Provision(firewall); requests.AssertAllCalledOnce(); }
public void TestProvisionUpdateScriptTypeDryrun() { var script = new Script( "hello-boot", ScriptType.PXE, "this is my script"); using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/list", Resources.VultrStartupScripts) ); new VultrScriptProvisioner(requests.Client).Provision(script, true); requests.AssertAllCalledOnce(); }
public void TestCreateStartupScript() { using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/create", "name=myscript&script=this+is+my+script&type=pxe", Resources.CreateStartupScript)); var result = requests.Client.StartupScript.CreateStartupScript( "myscript", "this is my script", ScriptType.pxe); Assert.Equal("5", result.StartupScript.SCRIPTID); requests.AssertAllCalledOnce(); }
public void TestMockGetStartupScripts() { using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/list", Resources.StartupScripts)); var scripts = requests.Client.StartupScript.GetStartupScripts(); Assert.Equal(2, scripts.StartupScripts.Count); Assert.Equal("3", scripts.StartupScripts["3"].SCRIPTID); Assert.Equal("5", scripts.StartupScripts["5"].SCRIPTID); Assert.Equal("pxe", scripts.StartupScripts["5"].type); requests.AssertAllCalledOnce(); }
public void TestProvisionDoNotUpdateUnchangedScript() { var script = new Script("hello-boot", ScriptType.Boot, "#!/bin/bash echo Hello World > /root/hello"); using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/list", Resources.VultrStartupScripts) ); new VultrScriptProvisioner(requests.Client).Provision(script); requests.AssertAllCalledOnce(); }
public void TestDestroyServerDryrun() { var server = new Server( new OperatingSystem(name: "Fedora 32 x64"), Plan, Region, userData: "test", label: "my new server"); using var requests = new MockVultrRequests( new HttpHandler("/regions/list?availability=yes", Resources.VultrRegionsList), new HttpHandler("/server/list", Resources.VultrServerList)); new VultrServerDestroyer(requests.Client).Destroy(server, true); requests.AssertAllCalledOnce(); }
public void TestDestroyFirewallDoesNotExist() { var firewall = new Firewall("my http firewall", new FirewallRule( IpType.V4, Protocol.TCP, "8080", "192.0.0.1", 20), new FirewallRule( IpType.V4, Protocol.TCP, "80", "cloudflare") ); using var requests = new MockVultrRequests( new HttpHandler( "/firewall/group_list", "{}")); new VultrFirewallDestroyer(requests.Client).Destroy(firewall); requests.AssertAllCalledOnce(); }
public void TestProvisionDryrun() { const string expected = "plan.cpu=2&plan.memory=4096&plan.type=SSD&" + "os.name=Fedora%2032%20x64&os.app=Fedora%2032%20x64&" + "os.iso=&dryrun=True"; using var requests = new MockVultrRequests( new HttpHandler( "provision", expected, "")); var input = new LineInputter(Resources.TestPlatformConfig); Assert.Equal(0, AProgram.Main(_testAssembly, input.ReadLine, "provision", "--apiurl", requests.Url, "--dryrun")); requests.AssertAllCalledOnce(); }
public void TestProvisionScript() { var script = new Script( "myscript", ScriptType.Boot, "this is my script"); using var requests = new MockVultrRequests( new HttpHandler("/startupscript/list"), new HttpHandler( "/startupscript/create", "name=myscript&script=this+is+my+script&type=boot", "{\"SCRIPTID\": 5}") ); new VultrScriptProvisioner(requests.Client).Provision(script); requests.AssertAllCalledOnce(); }
public void TestProvisionUpdateScriptContent() { var script = new Script( "hello-boot", ScriptType.Boot, "this is my script"); using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/list", Resources.VultrStartupScripts), new HttpHandler( "/startupscript/update", "SCRIPTID=3&script=this+is+my+script", "") ); new VultrScriptProvisioner(requests.Client).Provision(script); requests.AssertAllCalledOnce(); }
public void TestProvisionServerDryRun() { var server = new Server( new OperatingSystem(name: "Fedora 32 x64"), Plan, Region); using var requests = new MockVultrRequests( new HttpHandler( "/os/list", Resources.VultrOSList), new HttpHandler("/regions/list?availability=yes", Resources.VultrRegionsList), new HttpHandler("/plans/list?type=all", Resources.VultrPlansList), new HttpHandler("/sshkey/list", "{}"), new HttpHandler("/server/list") ); new VultrServerProvisioner(requests.Client).Provision(server, true); requests.AssertAllCalledOnce(); }
public void TestProvisionUpdateScriptType() { var script = new Script( "hello-boot", ScriptType.PXE, "this is my script"); using var requests = new MockVultrRequests( new HttpHandler( "/startupscript/list", Resources.VultrStartupScripts), new HttpHandler( "/startupscript/destroy", "SCRIPTID=3", ""), new HttpHandler( "/startupscript/create", "name=hello-boot&script=this+is+my+script&type=pxe", "{\"SCRIPTID\": 5}") ); new VultrScriptProvisioner(requests.Client).Provision(script); requests.AssertAllCalledOnce(); }
public void TestProvisionDoNotUpdateUnchangedServer() { var server = new Server( new OperatingSystem(name: "CentOS 6 x64"), new Plan(2, 4096, "SSD"), Region, label: "my new server", tag: "mytag" ); using var requests = new MockVultrRequests( new HttpHandler( "/os/list", Resources.VultrOSList), new HttpHandler("/regions/list?availability=yes", Resources.VultrRegionsList), new HttpHandler("/plans/list?type=all", Resources.VultrPlansList), new HttpHandler("/sshkey/list", "{}"), new HttpHandler( "/server/list", Resources.VultrServerList) ); new VultrServerProvisioner(requests.Client).Provision(server); requests.AssertAllCalledOnce(); }
public void TestDestroyFirewallNoRules() { var firewall = new Firewall("my http firewall", new FirewallRule( IpType.V4, Protocol.TCP, "8080", "192.0.0.1", 20), new FirewallRule( IpType.V4, Protocol.TCP, "80", "cloudflare") ); using var requests = new MockVultrRequests( new HttpHandler( "/firewall/group_list", Resources.VultrFirewallGroupList), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v4", "{}"), new HttpHandler( "/firewall/rule_list?FIREWALLGROUPID=1234abcd&direction=in&ip_type=v6", "{}"), new HttpHandler("/firewall/group_delete", "FIREWALLGROUPID=1234abcd", "")); new VultrFirewallDestroyer(requests.Client).Destroy(firewall); requests.AssertAllCalledOnce(); }