Ejemplo n.º 1
0
        public void ContributeAddsToBuilder()
        {
            // Uses git.properties file in test project
            var contrib = new GitInfoContributor();
            var builder = new InfoBuilder();
            contrib.Contribute(builder);

            var result = builder.Build();
            Assert.NotNull(result);
            var gitDict = result["git"] as Dictionary<string, object>;
            Assert.NotNull(gitDict);
            Assert.Equal(7, gitDict.Count);
            Assert.True(gitDict.ContainsKey("build"));
            Assert.True(gitDict.ContainsKey("branch"));
            Assert.True(gitDict.ContainsKey("commit"));
            Assert.True(gitDict.ContainsKey("closest"));
            Assert.True(gitDict.ContainsKey("dirty"));
            Assert.True(gitDict.ContainsKey("remote"));
            Assert.True(gitDict.ContainsKey("tags"));

            // Verify times are correctly converted
            var gitDict2 = gitDict["build"] as Dictionary<string, object>;
            Assert.NotNull(gitDict2);
            Assert.True(gitDict2.ContainsKey("time"));
            var time = gitDict2["time"];
            Assert.Equal(1499884839000, time);

            // Verify times are correctly converted
            var gitDict3 = gitDict["commit"] as Dictionary<string, object>;
            Assert.NotNull(gitDict3);
            Assert.True(gitDict3.ContainsKey("time"));
            time = gitDict3["time"];
            Assert.Equal(1496926022000, time);
        }
Ejemplo n.º 2
0
        public void ContributeAddsToBuilder()
        {
            appSettings.Add("info:NET:ASPNET:type", "Core");
            appSettings.Add("info:NET:ASPNET:version", "2.0.0");
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appSettings);
            var config   = configurationBuilder.Build();
            var settings = new AppSettingsInfoContributor(config);

            InfoBuilder builder = new InfoBuilder();

            settings.Contribute(builder);

            Dictionary <string, object> info = builder.Build();

            Assert.NotNull(info);
            Assert.Equal(2, info.Count);
            Assert.True(info.ContainsKey("application"));
            Assert.True(info.ContainsKey("NET"));

            var appNode = info["application"] as Dictionary <string, object>;

            Assert.NotNull(appNode);
            Assert.Equal("foobar", appNode["name"]);

            var netNode = info["NET"] as Dictionary <string, object>;

            Assert.NotNull(netNode);
            Assert.Equal("Core", netNode["type"]);

            Assert.NotNull(netNode["ASPNET"]);
        }
Ejemplo n.º 3
0
        public void ReturnsEmptyDictionary()
        {
            var builder = new InfoBuilder();
            var built   = builder.Build();

            Assert.NotNull(built);
            Assert.Empty(built);
        }
Ejemplo n.º 4
0
        public void ContributeAddsToBuilder()
        {
            var    appsettings = @"
{
    'info': {
        'application': {
            'name': 'foobar',
            'version': '1.0.0',
            'date': '5/1/2008',
            'time' : '8:30:52 AM'
        },
        'NET': {
            'type': 'Core',
            'version': '1.1.0',
            'ASPNET' : {
                'type': 'Core',
                'version': '1.1.0'
            }
        }
    }
}";
            var    path        = TestHelpers.CreateTempFile(appsettings);
            string directory   = Path.GetDirectoryName(path);
            string fileName    = Path.GetFileName(path);
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(directory);

            configurationBuilder.AddJsonFile(fileName);
            var config   = configurationBuilder.Build();
            var settings = new AppSettingsInfoContributor(config);

            InfoBuilder builder = new InfoBuilder();

            settings.Contribute(builder);

            Dictionary <string, object> info = builder.Build();

            Assert.NotNull(info);
            Assert.Equal(2, info.Count);
            Assert.True(info.ContainsKey("application"));
            Assert.True(info.ContainsKey("NET"));

            var appNode = info["application"] as Dictionary <string, object>;

            Assert.NotNull(appNode);
            Assert.Equal("foobar", appNode["name"]);

            var netNode = info["NET"] as Dictionary <string, object>;

            Assert.NotNull(netNode);
            Assert.Equal("Core", netNode["type"]);

            Assert.NotNull(netNode["ASPNET"]);
        }
Ejemplo n.º 5
0
        public void ConstributeWithConfigNull()
        {
            var         contributor = new AppSettingsInfoContributor(null);
            InfoBuilder builder     = new InfoBuilder();

            contributor.Contribute(builder);
            var result = builder.Build();

            Assert.NotNull(result);
            Assert.Equal(0, result.Count);
        }
Ejemplo n.º 6
0
        public void WithInfoSingleValueAddsValue()
        {
            var builder = new InfoBuilder();

            builder.WithInfo("foo", "bar");
            var built = builder.Build();

            Assert.NotNull(built);
            Assert.Single(built);
            Assert.Equal("bar", built["foo"]);
        }
        public void BuildAddsVersionInfo()
        {
            var contributor = new BuildInfoContributor();
            var builder     = new InfoBuilder();

            contributor.Contribute(builder);
            var results = builder.Build();

            Assert.True(results.ContainsKey("applicationVersionInfo"));
            Assert.NotNull(results["applicationVersionInfo"]);
            Assert.True(results.ContainsKey("steeltoeVersionInfo"));
            Assert.NotNull(results["steeltoeVersionInfo"]);
        }
Ejemplo n.º 8
0
        public void ReturnsPodInfoInsideCluster()
        {
            var builder     = new InfoBuilder();
            var contributor = new KubernetesInfoContributor(new FakePodUtilities(FakePodUtilities.SamplePod));

            contributor.Contribute(builder);
            var info = builder.Build()["kubernetes"] as Dictionary <string, object>;

            Assert.True(bool.Parse(info["inside"].ToString()));
            Assert.Equal("mynamespace", info["namespace"].ToString());
            Assert.Equal("mypod", info["podName"].ToString());
            Assert.Equal("mypodip", info["podIp"].ToString());
            Assert.Equal("myserviceaccount", info["serviceAccount"].ToString());
            Assert.Equal("mynode", info["nodeName"].ToString());
            Assert.Equal("myhostip", info["hostIp"].ToString());
        }
Ejemplo n.º 9
0
        public void WithInfoDictionaryAddsValues()
        {
            var builder = new InfoBuilder();
            Dictionary <string, object> items = new Dictionary <string, object>()
            {
                { "foo", "bar" },
                { "bar", 100 }
            };

            builder.WithInfo(items);
            var built = builder.Build();

            Assert.NotNull(built);
            Assert.Equal(2, built.Count);
            Assert.Equal("bar", built["foo"]);
            Assert.Equal(100, built["bar"]);
        }
Ejemplo n.º 10
0
        public void ReturnsNoPodInfoOutsideCluster()
        {
            var builder     = new InfoBuilder();
            var contributer = new KubernetesInfoContributor(new FakePodUtilities(null));

            contributer.Contribute(builder);
            var info = builder.Build()["kubernetes"] as Dictionary <string, object>;

            Assert.True(info.ContainsKey("inside"));
            Assert.False(bool.Parse(info["inside"].ToString()));
            Assert.False(info.ContainsKey("namespace"));
            Assert.False(info.ContainsKey("podName"));
            Assert.False(info.ContainsKey("podIp"));
            Assert.False(info.ContainsKey("serviceAccount"));
            Assert.False(info.ContainsKey("nodeName"));
            Assert.False(info.ContainsKey("hostIp"));
        }
Ejemplo n.º 11
0
        public void ContributeAddsToBuilder()
        {
            // Uses git.properties file in test project
            var contrib = new GitInfoContributor();
            var builder = new InfoBuilder();

            contrib.Contribute(builder);

            var result = builder.Build();

            Assert.NotNull(result);
            var gitDict = result["git"] as Dictionary <string, object>;

            Assert.NotNull(gitDict);
            Assert.Equal(7, gitDict.Count);
            Assert.True(gitDict.ContainsKey("build"));
            Assert.True(gitDict.ContainsKey("branch"));
            Assert.True(gitDict.ContainsKey("commit"));
            Assert.True(gitDict.ContainsKey("closest"));
            Assert.True(gitDict.ContainsKey("dirty"));
            Assert.True(gitDict.ContainsKey("remote"));
            Assert.True(gitDict.ContainsKey("tags"));

            var gitBuildDict = gitDict["build"] as Dictionary <string, object>;

            Assert.NotNull(gitBuildDict);
            Assert.True(gitBuildDict.ContainsKey("time"));

            // Verify that datetime values are normalized correctly
            var gitBuildTime = gitBuildDict["time"];

            Assert.Equal(DateTime.Parse("2017-07-12T18:40:39Z", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal), gitBuildTime);

            var gitCommitDict = gitDict["commit"] as Dictionary <string, object>;

            Assert.NotNull(gitCommitDict);
            Assert.True(gitCommitDict.ContainsKey("time"));

            // Verify that datetime values are normalized correctly
            var gitCommitTime = gitCommitDict["time"];

            Assert.Equal(DateTime.Parse("2017-06-08T12:47:02Z", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal), gitCommitTime);
        }
        public void ContributeAddsToBuilder()
        {
            var appsettings = new Dictionary <string, string>
            {
                ["info:application:name"]    = "foobar",
                ["info:application:version"] = "1.0.0",
                ["info:application:date"]    = "5/1/2008",
                ["info:application:time"]    = "8:30:52 AM",
                ["info:NET:type"]            = "Core",
                ["info:NET:version"]         = "1.1.0",
                ["info:NET:ASPNET:type"]     = "Core",
                ["info:NET:ASPNET:version"]  = "1.1.0"
            };
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appsettings);
            var config   = configurationBuilder.Build();
            var settings = new AppSettingsInfoContributor(config);

            var builder = new InfoBuilder();

            settings.Contribute(builder);

            var info = builder.Build();

            Assert.NotNull(info);
            Assert.Equal(2, info.Count);
            Assert.True(info.ContainsKey("application"));
            Assert.True(info.ContainsKey("NET"));

            var appNode = info["application"] as Dictionary <string, object>;

            Assert.NotNull(appNode);
            Assert.Equal("foobar", appNode["name"]);

            var netNode = info["NET"] as Dictionary <string, object>;

            Assert.NotNull(netNode);
            Assert.Equal("Core", netNode["type"]);

            Assert.NotNull(netNode["ASPNET"]);
        }
        public GetEntityDefaults(IExtensionReader extensionReader, IEntityDefaultReader entityDefaultReader, IRobotTemplateRelations robotTemplateRelations)
        {
            var cachedEntityDefaultsInfo = entityDefaultReader.GetAll().ToDictionary("d", ed => InfoBuilder.Build(extensionReader, robotTemplateRelations, ed));

            _message = Message.Builder.SetCommand(Commands.GetEntityDefaults).WithData(cachedEntityDefaultsInfo).Build();
        }