Example #1
0
        public EnvironmentConfiguration(YamlConfiguration yamlConfiguration)
        {
            Mode = Environment.GetEnvironmentVariable("NEST_INTEGRATION_TEST") != null ? TestMode.Integration : TestMode.Unit;

            ClusterFilter = Environment.GetEnvironmentVariable("NEST_INTEGRATION_CLUSTER");
            TestFilter    = Environment.GetEnvironmentVariable("NEST_TEST_FILTER");

            var version = Environment.GetEnvironmentVariable("NEST_INTEGRATION_VERSION");

            ElasticsearchVersion = string.IsNullOrWhiteSpace(version) ? yamlConfiguration.ElasticsearchVersion : version;
            if (ElasticsearchVersion == null)
            {
                throw new Exception("Elasticsearch Version could not be determined from env var NEST_INTEGRATION_VERSION nor the test yaml configuration");
            }

            var externalSeed = TryGetEnv("NEST_TEST_SEED", out var seed)
                                ? int.Parse(seed)
                                : yamlConfiguration.SeedProvidedExternally
                                        ? yamlConfiguration.Seed
                                        : (int?)null;

            SetExternalSeed(externalSeed, out var randomizer);

            TestOnlyOne = RandomBoolConfig("TEST_ONLY_ONE", randomizer, false);
            Random      = new RandomConfiguration
            {
                SourceSerializer = RandomBoolConfig("SOURCESERIALIZER", randomizer),
                TypedKeys        = RandomBoolConfig("TYPEDKEYS", randomizer),
                HttpCompression  = RandomBoolConfig("HTTPCOMPRESSION", randomizer),
            };
        }
Example #2
0
        /// <summary>
        /// Loads configuration by reading from the yaml and overriding specific configuration settings through
        /// environment variables set by the command line build.
        /// </summary>
        private static EnvironmentConfiguration LoadCommandLineConfiguration()
        {
            var yamlFile = Environment.GetEnvironmentVariable("NEST_YAML_FILE");

            if (string.IsNullOrWhiteSpace(yamlFile))
            {
                throw new Exception("expected NEST_YAML_FILE to be set when calling build.bat or build.sh");
            }
            if (!File.Exists(yamlFile))
            {
                throw new Exception($"expected {yamlFile} to exist on disk NEST_YAML_FILE seems misconfigured");
            }

            //load the test seed from the explicitly passed yaml file when running from FAKE
            var tempYamlConfiguration = new YamlConfiguration(yamlFile);

            return(new EnvironmentConfiguration(tempYamlConfiguration));
        }
        private static ITestConfiguration LoadConfiguration()
        {
            // The build script sets a FAKEBUILD env variable, so if it exists then
            // we must be running tests from the build script
            if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("FAKEBUILD")))
            {
                var yamlFile = Environment.GetEnvironmentVariable("NEST_YAML_FILE");
                if (!string.IsNullOrWhiteSpace(yamlFile) && File.Exists(yamlFile))
                {
                    //load the test seed from the explicitly passed yaml file when running from FAKE
                    var tempYamlConfiguration = new YamlConfiguration(yamlFile);
                    Environment.SetEnvironmentVariable("NEST_TEST_SEED", tempYamlConfiguration.Seed.ToString(CultureInfo.InvariantCulture),
                                                       EnvironmentVariableTarget.Process);
                    Console.WriteLine("--->" + tempYamlConfiguration.Seed);
                }
                return(new EnvironmentConfiguration());
            }


            var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
            var testsConfigurationFolder = FindTestsConfigurationFolder(directory);

            if (testsConfigurationFolder == null)
            {
                throw new Exception($"Tried to locate a parent test folder starting from  pwd:{directory.FullName}");
            }

            var localYamlFile = Path.Combine(testsConfigurationFolder.FullName, "tests.yaml");

            if (File.Exists(localYamlFile))
            {
                return(new YamlConfiguration(localYamlFile));
            }

            var defaultYamlFile = Path.Combine(testsConfigurationFolder.FullName, "tests.default.yaml");

            if (File.Exists(defaultYamlFile))
            {
                return(new YamlConfiguration(defaultYamlFile));
            }

            throw new Exception($"Tried to load a yaml file from {testsConfigurationFolder.FullName}");
        }
 public EnvironmentConfiguration(YamlConfiguration tempYamlConfiguration) : this()
 {
     ElasticsearchVersion = tempYamlConfiguration.ElasticsearchVersion;
     Seed = tempYamlConfiguration.Seed;
 }