Esempio n. 1
0
        public void GeneratesContent()
        {
            var metaData    = new Dictionary <string, string>();
            var networkData = new NetworkData(new Dictionary <string, object>());
            var userData    = new List <UserData>
            {
                new(UserDataContentType.CloudConfig, "", Encoding.UTF8),
                new(UserDataContentType.CloudConfig, "", Encoding.UTF8)
            };

            var options = new GenerateConfigDriveOptions();

            var dsMock = new Mock <IConfigDriveDataSource>();

            dsMock.Setup(x => x.GenerateConfigDriveContent(It.IsAny <IDictionary <string, string> >(),
                                                           networkData,
                                                           It.Is <IEnumerable <UserData> >(x => x.SequenceEqual(userData)), options)).Verifiable();

            var configDrive = new Dbosoft.CloudInit.ConfigDrive.ConfigDrive(dsMock.Object);

            configDrive.AddMetaData(metaData);
            configDrive.SetNetworkData(networkData);

            foreach (var data in userData)
            {
                configDrive.AddUserData(data);
            }

            configDrive.GenerateContent(options);

            dsMock.Verify();
        }
Esempio n. 2
0
        public void ValidateNetworkData()
        {
            var networkData = new NetworkData(new Dictionary <string, object>());

            var dsMock = new Mock <IConfigDriveDataSource>();

            dsMock.Setup(x => x.ValidateNetworkData(networkData)).Verifiable();

            var configDrive = new Dbosoft.CloudInit.ConfigDrive.ConfigDrive(dsMock.Object);

            configDrive.SetNetworkData(networkData);

            dsMock.Verify();
        }
Esempio n. 3
0
        public void ValidatesMetaData()
        {
            var metaData = new Dictionary <string, string>
            {
                { "a", "b" }
            };

            var dsMock = new Mock <IConfigDriveDataSource>();

            dsMock.Setup(x => x.ValidateMetaData(metaData)).Verifiable();

            var configDrive = new Dbosoft.CloudInit.ConfigDrive.ConfigDrive(dsMock.Object);

            configDrive.AddMetaData(metaData);

            dsMock.Verify();
        }
    public async Task WritesExpectedString(
        string metadata,
        string networkData,
        string userData,
        string expected)
    {
        var sb     = new StringBuilder();
        var writer = new ConfigDriveStringWriter(sb);

        var dsMock = new Mock <IConfigDriveDataSource>();

        dsMock.Setup(x => x.GenerateConfigDriveContent(
                         It.IsAny <IDictionary <string, string> >(),
                         It.IsAny <NetworkData>(),
                         It.IsAny <IEnumerable <UserData> >(),
                         It.IsAny <GenerateConfigDriveOptions>()))
        .ReturnsAsync(() =>
        {
            var res = new ConfigDriveContent("mediaName");

            if (metadata != null)
            {
                res.Files.Add(new ResultFile("meta", new MemoryStream(Encoding.UTF8.GetBytes(metadata))));
            }

            if (networkData != null)
            {
                res.Files.Add(new ResultFile("network", new MemoryStream(Encoding.UTF8.GetBytes(networkData))));
            }

            if (userData != null)
            {
                res.Files.Add(new ResultFile("user", new MemoryStream(Encoding.UTF8.GetBytes(userData))));
            }


            return(res);
        });

        var cd = new Dbosoft.CloudInit.ConfigDrive.ConfigDrive(dsMock.Object);

        await writer.WriteConfigDrive(cd);

        Assert.Equal(expected, sb.ToString());
    }