예제 #1
0
        public void WhenPathRooted_ShouldReturnRootPath( )
        {
            var    fixture = new Fixture( );
            var    p       = "/{0}/".With(fixture.Create("path"));
            string result  = LinuxPath.GetDirectoryName(p);

            Assert.Equal(p, result);
        }
예제 #2
0
        public void WhenPathRelative_ShouldReturnRelativePath( )
        {
            var    fixture = new Fixture( );
            var    p       = fixture.Create("path");
            string result  = LinuxPath.GetDirectoryName(p);

            Assert.Equal("./{0}/".With(p), result);
        }
예제 #3
0
        public void WhenPathRootedWithFileWithoutExtension_ShouldReturnDirectoryRootedPath( )
        {
            var    fixture = new Fixture( );
            var    p       = fixture.Create("path");
            var    pf      = "/{0}/file".With(p);
            string result  = LinuxPath.GetDirectoryName(pf);

            Assert.Equal("/{0}/".With(p), result);
        }
예제 #4
0
        public void WhenPathRelativeWithFileWithExtension_ShouldReturnDirectoryRelativePath( )
        {
            var    fixture = new Fixture( );
            var    p       = fixture.Create("path");
            var    pf      = "{0}/file.ext".With(p);
            string result  = LinuxPath.GetDirectoryName(pf);

            Assert.Equal("./{0}/".With(p), result);
        }
예제 #5
0
        public void WhenPathIsLevels_ShouldReturnRootPath( )
        {
            var    fixture = new Fixture( );
            var    pname   = fixture.Create("path");
            var    p       = "/some/path/deep/{0}/".With(pname);
            string result  = LinuxPath.GetDirectoryName(p);

            Assert.Equal("{0}".With(p), result);
        }
예제 #6
0
파일: LinuxPathTests.cs 프로젝트: sttt/madb
        public void GetDirectoryNameTest()
        {
            String result = LinuxPath.GetDirectoryName("/system/busybox");

            Assert.AreEqual <string>("/system/", result);

            result = LinuxPath.GetDirectoryName("/");
            Assert.AreEqual <string>("/", result);

            result = LinuxPath.GetDirectoryName("/system/xbin/");
            Assert.AreEqual <string>("/system/xbin/", result);
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileEntry"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="path">The path.</param>
        internal FileEntry(Device device, string path)
        {
            this.FetchTime = 0;
            this.Parent    = null;
            bool isDir = path.EndsWith(new string(LinuxPath.DirectorySeparatorChar, 1));

            this.Name     = isDir ? LinuxPath.GetDirectoryName(path) : LinuxPath.GetFileName(path);
            this.IsRoot   = path.Length == 1 && path[0] == LinuxPath.DirectorySeparatorChar;
            this.Type     = isDir ? FileListingService.FileTypes.Directory : FileListingService.FileTypes.File;
            this.Size     = 0;
            this.Children = new List <FileEntry>();
            this.Exists   = false;
            this.Device   = device;
        }
예제 #8
0
        public void WhenPathContainsInvalidCharacters_ShouldThrowException( )
        {
            int errorCount = 0;

            for (var x = 0; x < LinuxPathConsts.InvalidPathChars.Length; ++x)
            {
                try {
                    string result = LinuxPath.GetDirectoryName("/my-invalid-path/f-{0}".With(LinuxPathConsts.InvalidPathChars[x]));
                } catch (ArgumentException) {
                    errorCount++;
                }
            }

            Assert.Equal(LinuxPathConsts.InvalidPathChars.Length, errorCount);
        }
예제 #9
0
        public void GetDirectoryNameTest()
        {
            String result = LinuxPath.GetDirectoryName("/system/busybox");

            Assert.Equal("/system/", result);

            result = LinuxPath.GetDirectoryName("/");
            Assert.Equal("/", result);

            result = LinuxPath.GetDirectoryName("/system/xbin/");
            Assert.Equal("/system/xbin/", result);

            result = LinuxPath.GetDirectoryName("echo");
            Assert.Equal("./", result);

            result = LinuxPath.GetDirectoryName(null);
            Assert.Null(result);
        }
예제 #10
0
        public async Task NodeTask_Basic()
        {
            try
            {
                //-----------------------------------------------------------------
                // We're going to schedule simple node tasks for all cluster nodes that
                // touch a temporary file and then verify that the file was written
                // to the nodes and that the node task status indicates the the operation
                // succeeded.

                await DeleteExistingTasksAsync();

                // Create a string dictionary that maps cluster node names to the unique
                // name to use for the test tasks targeting each node.

                var nodeToTaskName = new Dictionary <string, string>();

                foreach (var node in fixture.Cluster.Nodes)
                {
                    nodeToTaskName.Add(node.Name, $"test-basic-{node.Name}-{CreateUuidString()}");
                }

                // Initalize a test folder on each node where the task will update a file
                // indicating that it ran and then submit a task for each node.

                foreach (var node in fixture.Cluster.Nodes)
                {
                    // Clear and recreate the node test folder.

                    node.Connect();
                    node.SudoCommand($"rm -rf {testFolderPath}");
                    node.SudoCommand($"mkdir -p {testFolderPath}");

                    // Create the node task for the target node.

                    var nodeTask = new V1NeonNodeTask();
                    var metadata = nodeTask.Metadata;
                    var spec     = nodeTask.Spec;

                    metadata.SetLabel(NeonLabel.RemoveOnClusterReset);

                    var filePath   = GetTestFilePath(node.Name);
                    var folderPath = LinuxPath.GetDirectoryName(filePath);

                    spec.Node             = node.Name;
                    spec.RetentionSeconds = 30;
                    spec.BashScript       =
                        $@"
set -euo pipefail

mkdir -p $NODE_ROOT{folderPath}
touch $NODE_ROOT{filePath}
";
                    await fixture.K8s.CreateClusterCustomObjectAsync <V1NeonNodeTask>(nodeTask, name : nodeToTaskName[node.Name]);
                }

                // Wait for all of the node tasks to report completion.

                var taskNames = new HashSet <string>();

                foreach (var taskName in nodeToTaskName.Values)
                {
                    taskNames.Add(taskName);
                }

                await NeonHelper.WaitForAsync(
                    async() =>
                {
                    foreach (var task in (await fixture.K8s.ListClusterCustomObjectAsync <V1NeonNodeTask>()).Items.Where(task => taskNames.Contains(task.Metadata.Name)))
                    {
                        switch (task.Status.Phase)
                        {
                        case V1NeonNodeTask.Phase.New:
                        case V1NeonNodeTask.Phase.Pending:
                        case V1NeonNodeTask.Phase.Running:

                            return(false);
                        }
                    }

                    return(true);
                },
                    timeout :      timeout,
                    pollInterval : pollInterval);

                //-----------------------------------------------------------------
                // Verify that the node tasks completeted successfully and are being
                // retained for a while.

                var nodeTasks = await fixture.K8s.ListClusterCustomObjectAsync <V1NeonNodeTask>();

                foreach (var task in nodeTasks.Items)
                {
                    if (taskNames.Contains(task.Metadata.Name))
                    {
                        Assert.Equal(V1NeonNodeTask.Phase.Success, task.Status.Phase);
                        Assert.Equal(0, task.Status.ExitCode);
                        Assert.Equal(string.Empty, task.Status.Output);
                        Assert.Equal(string.Empty, task.Status.Error);
                    }
                }

                //-----------------------------------------------------------------
                // Connect to each of the nodes and verify that the files touched by
                // the scripts actually exist.

                foreach (var node in fixture.Cluster.Nodes)
                {
                    var filePath = GetTestFilePath(node.Name);

                    // Clear and recreate the node test folder.

                    node.Connect();
                    Assert.True(node.FileExists(filePath));
                }
            }
            finally
            {
                // Remove the test folders on the nodes.

                foreach (var node in fixture.Cluster.Nodes)
                {
                    var filePath = GetTestFilePath(node.Name);

                    // Clear and recreate the node test folder.

                    node.Connect();
                    node.SudoCommand($"rm -rf {testFolderPath}");
                }
            }
        }
예제 #11
0
 public void GetDirectoryName()
 {
     Assert.Equal("/one/two", LinuxPath.GetDirectoryName("\\one\\two\\three.txt"));
     Assert.Equal("/one/two", LinuxPath.GetDirectoryName("/one/two/three.txt"));
 }
예제 #12
0
        public void WhenPathLengthIsRoot_ShouldReturnRootPath( )
        {
            string result = LinuxPath.GetDirectoryName("/");

            Assert.Equal("/", result);
        }
예제 #13
0
        public void WhenPathLengthIs1_ShouldReturnRelativePath( )
        {
            string result = LinuxPath.GetDirectoryName("a");

            Assert.Equal("./a/", result);
        }
예제 #14
0
        public void WhenPathIsNull_ShouldReturnNull( )
        {
            var result = LinuxPath.GetDirectoryName(null);

            Assert.Null(result);
        }