Exemplo n.º 1
0
        public void EqualsTest(EdgeAgentDockerModule mod1, EdgeAgentDockerModule mod2, bool areEqual)
        {
            // Act
            bool result = mod1.Equals(mod2);

            // Assert
            Assert.Equal(areEqual, result);
        }
Exemplo n.º 2
0
        public void MixedIModuleImplEqualsTest()
        {
            const string CreateOptions = "{\"HostConfig\":{\"PortBindings\":{\"8883/tcp\":[{\"HostPort\":\"8883\"}]}}}";
            const string Env           = "{\"var1\":{\"value\":\"val1\"}}";

            var fullModule = new EdgeAgentDockerModule(
                "docker",
                new DockerConfig("Foo", CreateOptions, Option.None <string>()),
                ImagePullPolicy.OnCreate,
                new ConfigurationInfo(),
                JsonConvert.DeserializeObject <IDictionary <string, EnvVal> >(Env),
                "version1");

            var simpleRuntimeModule = CreateEdgeAgentDockerRuntimeModule(new DockerConfig("Foo"));

            var fullRuntimeModule = CreateEdgeAgentDockerRuntimeModule(new DockerConfig(
                                                                           "Foo",
                                                                           "{\"ignore\": \"me\"}",
                                                                           Option.None <string>()));

            var runtimeModuleWithLabels = CreateEdgeAgentDockerRuntimeModule(new DockerConfig(
                                                                                 "Foo",
                                                                                 JsonConvert.SerializeObject(new
            {
                Labels = new Dictionary <string, object>
                {
                    [Constants.Labels.CreateOptions] = CreateOptions,
                    [Constants.Labels.Env]           = Env
                }
            }),
                                                                                 Option.None <string>()));

            var runtimeModuleWithMismatchedCreateOptionsLabel = CreateEdgeAgentDockerRuntimeModule(new DockerConfig(
                                                                                                       "Foo",
                                                                                                       JsonConvert.SerializeObject(new
            {
                Labels = new Dictionary <string, object>
                {
                    [Constants.Labels.CreateOptions] = "{\"a\":\"b\"}",
                    [Constants.Labels.Env]           = Env
                }
            }),
                                                                                                       Option.None <string>()));

            var runtimeModuleWithMismatchedEnvLabel = CreateEdgeAgentDockerRuntimeModule(new DockerConfig(
                                                                                             "Foo",
                                                                                             JsonConvert.SerializeObject(new
            {
                Labels = new Dictionary <string, object>
                {
                    [Constants.Labels.CreateOptions] = CreateOptions,
                    [Constants.Labels.Env]           = "{\"a\":{\"value\":\"b\"}}"
                }
            }),
                                                                                             Option.None <string>()));

            Assert.True(fullModule.Equals(simpleRuntimeModule));
            Assert.True(fullModule.Equals(fullRuntimeModule));
            Assert.True(fullModule.Equals(runtimeModuleWithLabels));

            Assert.False(fullModule.Equals(runtimeModuleWithMismatchedCreateOptionsLabel));
            Assert.False(fullModule.Equals(runtimeModuleWithMismatchedEnvLabel));
        }