Skip to content

Commit

Permalink
E2E Test for Bridge config update. (Azure#4814)
Browse files Browse the repository at this point in the history
In this PR I've added one test that verifies bridge config update + validation, end to end.
  • Loading branch information
vadim-kovalyov authored Apr 13, 2021
1 parent 5f0e4a0 commit 5e78034
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 2 deletions.
2 changes: 0 additions & 2 deletions test/Microsoft.Azure.Devices.Edge.Test/AuthorizationPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ namespace Microsoft.Azure.Devices.Edge.Test
{
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Devices.Client.Exceptions;
using Microsoft.Azure.Devices.Edge.Test.Common;
using Microsoft.Azure.Devices.Edge.Test.Common.Certs;
using Microsoft.Azure.Devices.Edge.Test.Common.Config;
using Microsoft.Azure.Devices.Edge.Test.Helpers;
using Microsoft.Azure.Devices.Edge.Util;
Expand Down
175 changes: 175 additions & 0 deletions test/Microsoft.Azure.Devices.Edge.Test/MqttBridgeConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright (c) Microsoft. All rights reserved.
namespace Microsoft.Azure.Devices.Edge.Test
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Test.Common;
using Microsoft.Azure.Devices.Edge.Test.Common.Config;
using Microsoft.Azure.Devices.Edge.Test.Helpers;
using Microsoft.Azure.Devices.Edge.Util.Test.Common.NUnit;
using NUnit.Framework;

[EndToEnd]
public class MqttBridgeConfig : SasManualProvisioningFixture
{
/// <summary>
/// Scenario:
/// - Create a deployment with broker and a bridge config.
/// - Update deployment with invalid bridge config.
/// - Validate the error message.
/// - Update deployment with new valid bridge config.
/// - Validate the successful result.
/// </summary>
[Test]
public async Task BridgeConfigUpdateTest()
{
CancellationToken token = this.TestToken;

EdgeDeployment deployment = await this.runtime.DeployConfigurationAsync(
builder =>
{
builder.GetModule(ModuleName.EdgeHub)
.WithEnvironment(new[]
{
("experimentalFeatures__enabled", "true"),
("experimentalFeatures__mqttBrokerEnabled", "true"),
})
// deploy with deny policy
.WithDesiredProperties(new Dictionary<string, object>
{
["mqttBroker"] = new
{
bridges = new[]
{
new
{
endpoint = "$upstream",
settings = new[]
{
new
{
direction = "in",
topic = "hello",
inPrefix = "/local/",
outPrefix = "/remote/"
}
}
}
}
}
});
},
token,
this.device.NestedEdge.IsNestedEdge);

EdgeModule edgeHub = deployment.Modules[ModuleName.EdgeHub];
await edgeHub.WaitForReportedPropertyUpdatesAsync(
new
{
properties = new
{
reported = new
{
lastDesiredStatus = new
{
code = 200,
description = string.Empty
}
}
}
},
token);

// deploy invalid bridge config. Missing `settings` property.
EdgeDeployment deployment2 = await this.runtime.DeployConfigurationAsync(
builder =>
{
builder.GetModule(ModuleName.EdgeHub)
.WithEnvironment(new[]
{
("experimentalFeatures__enabled", "true"),
("experimentalFeatures__mqttBrokerEnabled", "true"),
})
.WithDesiredProperties(new Dictionary<string, object>
{
["mqttBroker"] = new
{
bridges = new[]
{
new
{
endpoint = "$upstream"
}
}
}
});
},
token,
this.device.NestedEdge.IsNestedEdge);

EdgeModule edgeHub2 = deployment.Modules[ModuleName.EdgeHub];
await edgeHub2.WaitForReportedPropertyUpdatesAsync(
new
{
properties = new
{
reported = new
{
lastDesiredStatus = new
{
code = 400
}
}
}
},
token);

// deploy new valid bridge config.
EdgeDeployment deployment3 = await this.runtime.DeployConfigurationAsync(
builder =>
{
builder.GetModule(ModuleName.EdgeHub)
.WithEnvironment(new[]
{
("experimentalFeatures__enabled", "true"),
("experimentalFeatures__mqttBrokerEnabled", "true"),
})
.WithDesiredProperties(new Dictionary<string, object>
{
["mqttBroker"] = new
{
bridges = new[]
{
new
{
endpoint = "$upstream",
settings = new object[] { }
}
}
}
});
},
token,
this.device.NestedEdge.IsNestedEdge);

EdgeModule edgeHub3 = deployment.Modules[ModuleName.EdgeHub];
await edgeHub3.WaitForReportedPropertyUpdatesAsync(
new
{
properties = new
{
reported = new
{
lastDesiredStatus = new
{
code = 200,
description = string.Empty
}
}
}
},
token);
}
}
}

0 comments on commit 5e78034

Please sign in to comment.