コード例 #1
0
 public void TestTestConnectionFail()
 {
     using var requests = new MockVultrRequests(
               new HttpHandler("/", ""));
     Assert.Throws <HttpRequestException>(() =>
                                          new VultrPlatform("abc123", requests.Url).TestConnection());
 }
コード例 #2
0
        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&notify_activate=no&FIREWALLGROUPID=0",
                                      "{\"SUBID\": \"1312965\"}")
                      );
            new VultrServerProvisioner(requests.Client).Provision(server);
            requests.AssertAllCalledOnce();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 public void TestTestConnection()
 {
     using var requests = new MockVultrRequests(
               new HttpHandler(
                   "/account/info", Resources.VultrAccountInfo));
     new VultrPlatform("abc123", requests.Url).TestConnection();
 }
コード例 #5
0
        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();
        }
コード例 #6
0
        public void TestGetRegionId(int id, string name)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/regions/list", Resources.VultrRegionsList));

            Assert.Equal(id, requests.Client.Region.GetRegionId(name));
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        public void TestGetPlanId(int id, int cpu, int ram, string type)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/plans/list", Resources.VultrPlansList));

            var provisioner = new VultrServerProvisioner(requests.Client);

            Assert.Equal(id, provisioner.GetPlanId(
                             new Plan(cpu, ram, type)));
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        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();
        }
コード例 #16
0
        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();
        }
コード例 #17
0
        public void TestCreateOs(int id, string name)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/os/list", Resources.VultrOSList));

            var os = VultrOperatingSystem.CreateOs(name, requests.Client);

            Assert.Equal(id, os.OsId);
            Assert.Null(os.Appid);
            Assert.Null(os.IsoId);
            Assert.Null(os.ScriptId);
            Assert.Null(os.SnapshotId);
        }
コード例 #18
0
        public void TestCreateIso(string name, int id)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/iso/list", Resources.VultrISOList));

            var iso = VultrOperatingSystem.CreateIso(name, requests.Client);

            Assert.Equal(159, iso.OsId);
            Assert.Equal(id, iso.IsoId);
            Assert.Null(iso.Appid);
            Assert.Null(iso.ScriptId);
            Assert.Null(iso.SnapshotId);
        }
コード例 #19
0
        public void TestCreateApp(int id, string name)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/app/list", Resources.VultrAppList));

            var app = VultrOperatingSystem.CreateApp(name, requests.Client);

            Assert.Equal(186, app.OsId);
            Assert.Equal(id, app.Appid);
            Assert.Null(app.IsoId);
            Assert.Null(app.ScriptId);
            Assert.Null(app.SnapshotId);
        }
コード例 #20
0
        public void TestCreateSnapshot(string id)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/snapshot/list", Resources.VultrSnapshotList));

            var snapshot = VultrOperatingSystem.CreateSnapshot(id, requests.Client);

            Assert.Equal(164, snapshot.OsId);
            Assert.Equal(id, snapshot.SnapshotId);
            Assert.Null(snapshot.Appid);
            Assert.Null(snapshot.IsoId);
            Assert.Null(snapshot.ScriptId);
        }
コード例 #21
0
        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();
        }
コード例 #22
0
        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();
        }
コード例 #23
0
ファイル: ProgramTest.cs プロジェクト: okinta/agrix
        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();
        }
コード例 #24
0
        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();
        }
コード例 #25
0
        public void TestCreateScript(string name, int id)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/os/list", Resources.VultrOSList),
                      new HttpHandler(
                          "/startupscript/list", Resources.VultrStartupScripts));

            var script = VultrOperatingSystem.CreateScript(
                "FreeBSD 11 x64", name, requests.Client);

            Assert.Equal(230, script.OsId);
            Assert.Equal(id, script.ScriptId);
            Assert.Null(script.Appid);
            Assert.Null(script.IsoId);
            Assert.Null(script.SnapshotId);
        }
コード例 #26
0
        public void TestGetOsApp()
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/app/list", Resources.VultrAppList));

            var provisioner = new VultrServerProvisioner(requests.Client);
            var server      = new Server(
                new OperatingSystem("LAMP on CentOS 7 x64"),
                Plan, Region);
            var os = provisioner.GetOs(server);

            Assert.Equal(186, os.OsId);
            Assert.Equal(41, os.Appid);
            Assert.Null(os.IsoId);
            Assert.Null(os.ScriptId);
            Assert.Null(os.SnapshotId);
        }
コード例 #27
0
        public void TestGetIso()
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/iso/list", Resources.VultrISOList));

            var provisioner = new VultrServerProvisioner(requests.Client);
            var server      = new Server(
                new OperatingSystem(iso: "installcoreos.iso"),
                Plan, Region);
            var os = provisioner.GetOs(server);

            Assert.Equal(159, os.OsId);
            Assert.Null(os.Appid);
            Assert.Null(os.ScriptId);
            Assert.Null(os.SnapshotId);
            Assert.True(os.IsoId > 0);
        }
コード例 #28
0
        public void TestGetOs(int id, string name)
        {
            using var requests = new MockVultrRequests(
                      new HttpHandler(
                          "/os/list", Resources.VultrOSList));

            var provisioner = new VultrServerProvisioner(requests.Client);
            var server      = new Server(
                new OperatingSystem(name: name),
                Plan, Region);
            var os = provisioner.GetOs(server);

            Assert.Equal(id, os.OsId);
            Assert.Null(os.Appid);
            Assert.Null(os.IsoId);
            Assert.Null(os.ScriptId);
            Assert.Null(os.SnapshotId);
        }
コード例 #29
0
        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();
        }
コード例 #30
0
        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();
        }