public WebServerTests(
     DockerFixture fixture,
     ITestOutputHelper helper)
 {
     _helper = helper;
     _database = fixture.GenerateDatabase(Guid.NewGuid().ToString("N"));
 }
Пример #2
0
        /// <summary>
        ///  Start bitcoind and nbxplorer in the backgroud.
        /// </summary>
        /// <param name="dockerFixture"></param>
        /// <param name="output"></param>
        /// <param name="caller"></param>
        /// <returns></returns>
        public static async Task <ExplorerClient> StartExplorerFixtureAsync(this DockerFixture dockerFixture, string caller)
        {
            var ports = new int[2];

            Support.Utils.FindEmptyPort(ports);
            var dataPath = Path.GetFullPath(caller);

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            else
            {
                Directory.Delete(dataPath, true);
                Directory.CreateDirectory(dataPath);
            }
            var env = new Dictionary <string, object>()
            {
                {
                    "BITCOIND_RPC_AUTH",
                    Constants.BitcoindRPCAuth
                },
                { "BITCOIND_RPC_USER", Constants.BitcoindRPCUser },
                { "BITCOIND_RPC_PASS", Constants.BitcoindRPCPass },
                { "BITCOIND_RPC_PORT", ports[0] },
                { "NBXPLORER_PORT", ports[1] },
                { "DATA_PATH", dataPath }
            };
            var envFile = Path.Join(dataPath, "env.sh");

            using (TextWriter w = File.AppendText(envFile))
            {
                foreach (var kv in env)
                {
                    w.WriteLine($"export {kv.Key}='{kv.Value}'");
                }
            }
            await dockerFixture.InitAsync(() => new DockerFixtureOptions
            {
                DockerComposeFiles    = new[] { "docker-compose.base.yml" },
                EnvironmentVariables  = env,
                DockerComposeDownArgs = "--remove-orphans --volumes",
                // we need this because c-lightning is not working well with bind mount.
                // If we use volume mount instead, this is the only way to recreate the volume at runtime.
                DockerComposeUpArgs = "--renew-anon-volumes",
                StartupTimeoutSecs  = 400,
                LogFilePath         = Path.Join(dataPath, "docker-compose.log"),
                CustomUpTest        = o =>
                {
                    return
                    (o.Any(x => x.Contains("BTC: Node state changed: NBXplorerSynching => Ready")));   // nbx is up
                }
            });

            var networkProvider = new NRustLightningNetworkProvider(NetworkType.Regtest);
            var btcNetwork      = networkProvider.GetByCryptoCode("BTC");

            return(new ExplorerClient(btcNetwork.NbXplorerNetwork, new Uri($"http://localhost:{ports[1]}")));
        }
        public void Dispose_CallsDown_WhenRun()
        {
            var compose = new Mock <IDockerCompose>();

            compose.Setup(c => c.PauseMs).Returns(NumberOfMsInOneSec);
            compose.Setup(c => c.Up()).Returns(Task.Delay(ComposeUpRunDurationMs));
            compose.SetupSequence(c => c.Ps())
            .Returns(new[] { "--------" })
            .Returns(new[] { "--------", " Up ", " Up " });

            var fixture = new DockerFixture(null);

            fixture.Init(new[] { Path.GetTempFileName() }, "up", "down", 120, null, compose.Object);
            fixture.Dispose();

            compose.Verify(c => c.Down(), Times.Once);
        }
Пример #4
0
        public Test_ComposedFixture(ComposedFixture composedFixture)
        {
            this.composedFixture = composedFixture;

            var fixtureStatus = composedFixture.Start(
                () =>
            {
                // NOTE: Adding this one first because it clears the local Docker
                //       state when it starts and we want the containers started
                //       by the other fixtures to be unmolested.

                composedFixture.AddFixture("docker", new DockerFixture());

                composedFixture.AddFixture("aspNet", new AspNetFixture(),
                                           aspNetFixture =>
                {
                    aspNetFixture.StartAsComposed <Startup>();
                });

                composedFixture.AddFixture("container", new ContainerFixture(),
                                           containerFixture =>
                {
                    containerFixture.StartAsComposed("my-container", $"{NeonHelper.NeonLibraryBranchRegistry}/test:latest");
                });

                composedFixture.AddFixture("hosts", new HostsFixture());

                composedFixture.AddFixture("nats", new NatsFixture(),
                                           natsFixture =>
                {
                    natsFixture.StartAsComposed();
                });
            });

            this.aspNetFixture    = (AspNetFixture)composedFixture["aspNet"];
            this.dockerFixture    = (DockerFixture)composedFixture["docker"];
            this.containerFixture = (ContainerFixture)composedFixture["container"];
            this.hostsFixture     = (HostsFixture)composedFixture["hosts"];
            this.natsFixture      = (NatsFixture)composedFixture["nats"];

            if (fixtureStatus == TestFixtureStatus.Started)
            {
                hostsFixture.AddHostAddress("foo.bar", "127.1.2.3");
            }
        }
Пример #5
0
 public GivenBucketDoesNotExists(DockerFixture dockerFixture)
     : base(dockerFixture)
 {
     _sut = new InfluxDBSink(new InfluxDBSinkOptions()
     {
         ApplicationName = $"Test_{nameof(GivenBucketDoesNotExists)}",
         ConnectionInfo  = new InfluxDBConnectionInfo()
         {
             Uri                     = new Uri("http://127.0.0.1:8086"),
             BucketName              = "logs",
             OrganizationId          = "88e1f5a5ad074d9e", // Organization Id - unique id can be found under Profile > About > Common Ids
             CreateBucketIfNotExists = true,
             //Username = "******",
             //Password = "******",
             AllAccessToken        = "bGfBKhSycNiUOia4k7peib2jHFewkz3o6Hv2uz1xAoUcdnEFRW7cHn03KICySLemA4VPZKvc0CwzSQT8GNl2DA==",
             BucketRetentionPeriod = TimeSpan.FromDays(1)
         },
     });
 }
        public void InitOnce_InitialisesDockerOnce_WhenCalledTwice()
        {
            var compose = new Mock <IDockerCompose>();

            compose.Setup(c => c.PauseMs).Returns(NumberOfMsInOneSec);
            compose.Setup(c => c.Up()).Returns(Task.Delay(ComposeUpRunDurationMs));
            compose.SetupSequence(c => c.Ps())
            .Returns(new[] { "--------" })
            .Returns(new[] { "--------", " Up ", " Up " });

            var tmp     = Path.GetTempFileName();
            var fixture = new DockerFixture(null);

            fixture.InitOnce(() => new DockerFixtureOptions {
                DockerComposeFiles = new[] { tmp }
            }, compose.Object);
            fixture.InitOnce(() => new DockerFixtureOptions {
                DockerComposeFiles = new[] { tmp }
            }, compose.Object);
            compose.Verify(c => c.Init(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            compose.Verify(c => c.Up(), Times.Once);
        }
 public GetAllAggregateNamesQueryTests(DockerFixture fixture)
 {
     this.sut = new GetAllAggregateNamesQuery(fixture.ConnectionStringProvider);
 }
Пример #8
0
 public UniqueValueGeneratingTests(DockerFixture fixture, ITestOutputHelper output)
 {
     _output   = output;
     _database = fixture.GenerateDatabase(Guid.NewGuid().ToString("N"));
 }
Пример #9
0
 public PNetClientShould(DockerFixture dockerFixture)
 {
     _dockerFixture = dockerFixture;
 }
Пример #10
0
        public static async Task <Clients> StartLNTestFixtureAsync(this DockerFixture dockerFixture, string caller, bool useCachedData = false)
        {
            var ports = new int[5];

            Support.Utils.FindEmptyPort(ports);
            var dataPath = Path.GetFullPath(caller);

            if (Directory.Exists(dataPath) && !useCachedData)
            {
                Directory.Delete(dataPath, true);
            }
            Directory.CreateDirectory(dataPath);

            var env = new Dictionary <string, object>()
            {
                {
                    "BITCOIND_RPC_AUTH",
                    Constants.BitcoindRPCAuth
                },
                { "BITCOIND_RPC_USER", Constants.BitcoindRPCUser },
                { "BITCOIND_RPC_PASS", Constants.BitcoindRPCPass },
                { "BITCOIND_RPC_PORT", ports[0] },
                { "LND_REST_PORT", ports[1] },
                { "LIGHTNINGD_RPC_PORT", ports[2] },
                { "HTTP_PORT", ports[3] },
                { "NBXPLORER_PORT", ports[4] },
                { "DATA_PATH", dataPath }
            };
            var envFile = Path.Join(dataPath, "env.sh");

            using (TextWriter w = File.AppendText(envFile))
            {
                foreach (var kv in env)
                {
                    w.WriteLine($"export {kv.Key}='{kv.Value}'");
                }
            }
            await dockerFixture.InitAsync(() => new DockerFixtureOptions
            {
                DockerComposeFiles    = new[] { "docker-compose.yml" },
                EnvironmentVariables  = env,
                DockerComposeDownArgs = "--remove-orphans --volumes",
                // we need this because c-lightning is not working well with bind mount.
                // If we use volume mount instead, this is the only way to recreate the volume at runtime.
                DockerComposeUpArgs = "--renew-anon-volumes",
                StartupTimeoutSecs  = 400,
                LogFilePath         = Path.Join(dataPath, "docker-compose.log"),
                CustomUpTest        = o =>
                {
                    return
                    (o.Any(x => x.Contains("Now listening on: http://0.0.0.0:9735")) && // nrustlightning is up
                     o.Any(x => x.Contains("PeerManagerProvider started")) &&    // ditto
                     o.Any(x => x.Contains("Server started with public key")) &&    // lightningd is up
                     o.Any(x => x.Contains("BTC: Node state changed: NBXplorerSynching => Ready")) &&    // nbx is up
                     o.Any(x => x.Contains("BTCN: Server listening on")));      // lnd is up
                }
            });

            var networkProvider      = new NRustLightningNetworkProvider(NetworkType.Regtest);
            var btcNetwork           = networkProvider.GetByCryptoCode("BTC");
            var lndMacaroonPath      = Path.Join(dataPath, ".lnd", "chain", "bitcoin", "regtest", "admin.macaroon");
            var lndTlsCertThumbPrint = GetCertificateFingerPrintHex(Path.Join(dataPath, ".lnd", "tls.cert"));
            var clients = new Clients(
                new RPCClient($"{Constants.BitcoindRPCUser}:{Constants.BitcoindRPCPass}", new Uri($"http://localhost:{ports[0]}"), NBitcoin.Network.RegTest),
                (LndClient)LightningClientFactory.CreateClient($"type=lnd-rest;macaroonfilepath={lndMacaroonPath};certthumbprint={lndTlsCertThumbPrint};server=https://localhost:{ports[1]}", NBitcoin.Network.RegTest),
                (CLightningClient)LightningClientFactory.CreateClient($"type=clightning;server=tcp://127.0.0.1:{ports[2]}", NBitcoin.Network.RegTest),
                new NRustLightningClient($"http://localhost:{ports[3]}", btcNetwork),
                new ExplorerClient(btcNetwork.NbXplorerNetwork, new Uri($"http://localhost:{ports[4]}"))
                );

            return(clients);
        }