mirror of
				https://github.com/tmux-plugins/tpm.git
				synced 2025-11-04 00:16:05 +00:00 
			
		
		
		
	First version of tests
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					**/.vagrant/
 | 
				
			||||||
							
								
								
									
										29
									
								
								test/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								test/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					# Tmux
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# VERSION 0.0.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FROM ubuntu:trusty
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MAINTAINER Bruno Sutic "bruno.sutic@gmail.com"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN apt-get update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN apt-get install -y git-core
 | 
				
			||||||
 | 
					RUN apt-get install -y expect
 | 
				
			||||||
 | 
					RUN apt-get install -y python-software-properties software-properties-common
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# sshd
 | 
				
			||||||
 | 
					RUN apt-get install -y openssh-server
 | 
				
			||||||
 | 
					RUN mkdir /var/run/sshd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Enabling passwordless ssh login with `docker_ssh.key` private key.
 | 
				
			||||||
 | 
					RUN mkdir -p /root/.ssh/
 | 
				
			||||||
 | 
					RUN echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVmzBG5v7cO9IScGLIzlhGlHNFhXzy87VfaPzru7qnIIdQ1e9FEKvtqEws8hVixnCUdviwX5lvcMk4Ef4Tbrmj3dyF0zFtYbjiTSyl/XQlF68DQlc2sTAdHy96wJHvh7ky511tKJzzyWwSqeef4WjeVK28TqcGnq1up0S7saFO0dJh6OfDAg2cDmhyweR3VgT0vZJyrDV7hte95MBCdK+Gp7fdCyEZcWm3S1DBFaeBqHzzt/Y/njAVKbYL9TIVPum8iMg0rMiLi9ShfP+dT5Xud5Oa3dcN2OWhiDfJw5pfhFJWd44cJ/uGRwQpvNs/PNKsYABhgLlTMUH4iawhu1Xb' > /root/.ssh/authorized_keys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# install latest Tmux 1.9a
 | 
				
			||||||
 | 
					RUN add-apt-repository ppa:pi-rho/dev
 | 
				
			||||||
 | 
					RUN apt-get update
 | 
				
			||||||
 | 
					RUN apt-get install -y tmux=1.9a-1~ppa1~t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					EXPOSE 22
 | 
				
			||||||
 | 
					CMD /usr/sbin/sshd -D
 | 
				
			||||||
							
								
								
									
										16
									
								
								test/Vagrantfile
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								test/Vagrantfile
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					Vagrant.require_version '>= 1.6.0'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VAGRANTFILE_API_VERSION = '2'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
 | 
				
			||||||
 | 
					  config.vm.provider 'docker' do |d|
 | 
				
			||||||
 | 
					    d.build_dir = '.'
 | 
				
			||||||
 | 
					    d.has_ssh = true
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # tpm is synced with `/root/tmux_plugin_manager` in vagrant
 | 
				
			||||||
 | 
					  config.vm.synced_folder '../', '/root/tmux_plugin_manager'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  config.ssh.username = 'root'
 | 
				
			||||||
 | 
					  config.ssh.private_key_path = 'docker_ssh.key'
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
							
								
								
									
										27
									
								
								test/docker_ssh.key
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								test/docker_ssh.key
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					-----BEGIN RSA PRIVATE KEY-----
 | 
				
			||||||
 | 
					MIIEpQIBAAKCAQEA1ZswRub+3DvSEnBiyM5YRpRzRYV88vO1X2j867u6pyCHUNXv
 | 
				
			||||||
 | 
					RRCr7ahMLPIVYsZwlHb4sF+Zb3DJOBH+E265o93chdMxbWG44k0spf10JRevA0JX
 | 
				
			||||||
 | 
					NrEwHR8vesCR74e5MuddbSic88lsEqnnn+Fo3lStvE6nBp6tbqdEu7GhTtHSYejn
 | 
				
			||||||
 | 
					wwINnA5ocsHkd1YE9L2Scqw1e4bXveTAQnSvhqe33QshGXFpt0tQwRWngah887f2
 | 
				
			||||||
 | 
					P54wFSm2C/UyFT7pvIjINKzIi4vUoXz/nU+V7neTmt3XDdjloYg3ycOaX4RSVneO
 | 
				
			||||||
 | 
					HCf7hkcEKbzbPzzSrGAAYYC5UzFB+ImsIbtV2wIDAQABAoIBAQCjROxgtX2Gft7y
 | 
				
			||||||
 | 
					Ix8Ol9IXmK6HLCI2XZt7ovb3hFWGGzHy0qMBql2P2Tzoed1o038Hq+woe9n+uTnE
 | 
				
			||||||
 | 
					dtQ6rD6PByzgyW2VSsWTjCOdeJ5HH9Qw7ItXDZZWHBkhfYHOkXI4e2oI3qshGAtY
 | 
				
			||||||
 | 
					NLALn7KVhioJriCyyaSM2KOLx5khcY+EJ1inQfwQJKqPGsdKc72liz07T8ifRj+m
 | 
				
			||||||
 | 
					NLKtwrxlK3IXYfIdgLp/1pCKdrC80DhprMsD4xvNgq4pCR9jd4FoqM9t/Up5ppTm
 | 
				
			||||||
 | 
					+p6A/bDwdIPh6cFFeyMP+G3+bTlW1Gg7RLoNCc6qh53WWVgEOQqdLHcQ8Ge4RLmb
 | 
				
			||||||
 | 
					wLUmnRuRAoGBAPfXYfjpPZi8rPIQpux13Bs7xaS1/Fa9WqrEfrPptFdUVHeFCGY8
 | 
				
			||||||
 | 
					qOUVewPviHdbs0nB71Ynk9/e96agFYijQdqTQzVnpYI4i8GiGk5gPMiB2UYeJ/HZ
 | 
				
			||||||
 | 
					mIB3jtWyf6Z/GO0hJ1a6mX0XD3zJGNqFaiwqaYgdO1Fwh9gcH3O2lHyjAoGBANyj
 | 
				
			||||||
 | 
					TGDBYHpxPu6uKcGreLd0SgO61PEj7aOSNfrBB2PK83A+zjZCFZRIWqjfrkxGG6+a
 | 
				
			||||||
 | 
					2WuHbEHuCGvu2V5juHYxbAD/38iV/lQl/2xyvN1eR/baE3US06qn6idxjnmeNZDy
 | 
				
			||||||
 | 
					DelAx1RGuEvLX1TNAzDTxBwYyzH3W2RpKAUAD11pAoGAN38YJhd8Pn5JL68A4cQG
 | 
				
			||||||
 | 
					dGau/BHwHjAqZEC5qmmzgzaT72tvlQ0SOLHVqOzzHt7+x45QnHciSqfvxnTkPYNp
 | 
				
			||||||
 | 
					FJuTGhtKWV12FfbJczFjivZgg63u/d3eoy2iY0GkCdE98KNS3r3L7tHCGwwgr5Xe
 | 
				
			||||||
 | 
					T2Nz3BHHnZXYJVEuzcddeocCgYEAnhDjPAHtw2p0Inxlb9kPb6aBC/ECcwtBSUkL
 | 
				
			||||||
 | 
					IOy/BZA1HPnxs89eNFAtmwQ8k2o6lXDDSJTJSuZj5CdGVKfuU8aOUJz/Tm2eudxL
 | 
				
			||||||
 | 
					A/+jLJhJyCBthhcJyx3m04E4CAr+5ytyKeP9qXPMvoghcNg66/UabuKYV+CU+feX
 | 
				
			||||||
 | 
					8xUa7NkCgYEAlX8HGvWMmiG+ZRFB//3Loy87bBxGlN0pUtCEScabZxdB2HkI9Vp7
 | 
				
			||||||
 | 
					Yr67QIZ3y7T88Mhkwam54JCjiV+3TZbSyRMOjkqf7UhTCZC6hHNqdUnlpv4bJWeW
 | 
				
			||||||
 | 
					i5Eun8ltYxBnemNc2QGxA4r+KCspi+pRvWNGzL3PFVBGXiLsmOMul78=
 | 
				
			||||||
 | 
					-----END RSA PRIVATE KEY-----
 | 
				
			||||||
							
								
								
									
										23
									
								
								test/run
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										23
									
								
								test/run
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					run_vagrant() {
 | 
				
			||||||
 | 
					    vagrant up --provider=docker
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					stop_vagrant() {
 | 
				
			||||||
 | 
					    vagrant destroy -f
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					run_tests() {
 | 
				
			||||||
 | 
					    # actually this test file should be run inside vagrant
 | 
				
			||||||
 | 
					    $CURRENT_DIR/tests/test_plugin_installation.sh
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					main() {
 | 
				
			||||||
 | 
					    run_vagrant
 | 
				
			||||||
 | 
					    run_tests
 | 
				
			||||||
 | 
					    stop_vagrant
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					main
 | 
				
			||||||
							
								
								
									
										35
									
								
								test/tests/expect_successful_plugin_download
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										35
									
								
								test/tests/expect_successful_plugin_download
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env expect
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# disables script output
 | 
				
			||||||
 | 
					log_user 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					spawn tmux
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Waiting for tmux to attach. If this is not done, next command, `send` will
 | 
				
			||||||
 | 
					# not work properly.
 | 
				
			||||||
 | 
					sleep 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# this is tmux prefix + I
 | 
				
			||||||
 | 
					send "I"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# cloning might take a while
 | 
				
			||||||
 | 
					set timeout 15
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					expect {
 | 
				
			||||||
 | 
					  "Downloading bruno-/tmux_example_plugin" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    expect {
 | 
				
			||||||
 | 
					      "bruno-/tmux_example_plugin download success" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expect { "Done, press ENTER to continue" { exit } }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  timeout {
 | 
				
			||||||
 | 
					    puts "Plugin update timeout";
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										46
									
								
								test/tests/helpers.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								test/tests/helpers.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set_tmux_conf_helper() {
 | 
				
			||||||
 | 
					    > ~/.tmux.conf  # empty filename
 | 
				
			||||||
 | 
					    while read -r line; do
 | 
				
			||||||
 | 
					        echo $line >> ~/.tmux.conf
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create_test_plugin_helper() {
 | 
				
			||||||
 | 
					    local plugin_path="$HOME/.tmux/plugins/tmux_test_plugin/"
 | 
				
			||||||
 | 
					    rm -rf $plugin_path
 | 
				
			||||||
 | 
					    mkdir -p $plugin_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while read -r line; do
 | 
				
			||||||
 | 
					        echo $line >> "$plugin_path/test_plugin.tmux"
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
 | 
					    chmod +x "$plugin_path/test_plugin.tmux"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					teardown_helper() {
 | 
				
			||||||
 | 
					    rm ~/.tmux.conf
 | 
				
			||||||
 | 
					    rm -rf ~/.tmux/
 | 
				
			||||||
 | 
					    tmux kill-server >/dev/null 2>&1
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					check_dir_exists_helper() {
 | 
				
			||||||
 | 
					    local dir_path=$1
 | 
				
			||||||
 | 
					    if [ -d "$dir_path" ]; then
 | 
				
			||||||
 | 
					        return 0
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        return 1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit_value_helper() {
 | 
				
			||||||
 | 
					    if $FAIL; then
 | 
				
			||||||
 | 
					        echo
 | 
				
			||||||
 | 
					        echo "Test failed"
 | 
				
			||||||
 | 
					        exit 1
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        echo
 | 
				
			||||||
 | 
					        echo "Test finished successfully"
 | 
				
			||||||
 | 
					        exit 0
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										30
									
								
								test/tests/test_plugin_installation.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								test/tests/test_plugin_installation.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					source $CURRENT_DIR/helpers.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FAIL=false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test_plugin_installation() {
 | 
				
			||||||
 | 
						set_tmux_conf_helper <<- HERE
 | 
				
			||||||
 | 
						set -g @tpm_plugins "bruno-/tmux_example_plugin"
 | 
				
			||||||
 | 
						run-shell '~/tmux_plugin_manager/tpm'
 | 
				
			||||||
 | 
						HERE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # opens tmux and test it with `expect`
 | 
				
			||||||
 | 
					  $CURRENT_DIR/expect_successful_plugin_download ||
 | 
				
			||||||
 | 
					      (echo "Tmux plugin installation fails" >&2; FAIL=true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # check plugin dir exists after download
 | 
				
			||||||
 | 
					  check_dir_exists_helper "/root/.tmux/plugins/tmux_example_plugin/" ||
 | 
				
			||||||
 | 
					      (echo "Plugin download fails" >&2; FAIL=true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						teardown_helper
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					main() {
 | 
				
			||||||
 | 
					    test_plugin_installation
 | 
				
			||||||
 | 
					    exit_value_helper
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					main
 | 
				
			||||||
							
								
								
									
										36
									
								
								test/tests/test_plugin_sourcing.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										36
									
								
								test/tests/test_plugin_sourcing.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					source $CURRENT_DIR/helpers.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FAIL=false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					check_binding_defined() {
 | 
				
			||||||
 | 
					    local binding=$1
 | 
				
			||||||
 | 
					    tmux list-keys | grep -q "$binding"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test_plugin_sourcing() {
 | 
				
			||||||
 | 
						set_tmux_conf_helper <<- HERE
 | 
				
			||||||
 | 
						set -g @tpm_plugins "doesnt_matter/tmux_test_plugin"
 | 
				
			||||||
 | 
						# change this
 | 
				
			||||||
 | 
						run-shell '~/tmux_plugin_manager/tpm'
 | 
				
			||||||
 | 
						HERE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						create_test_plugin_helper <<- HERE
 | 
				
			||||||
 | 
						tmux bind-key R run-shell foo_command
 | 
				
			||||||
 | 
						HERE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  tmux new-session -d  # tmux starts detached
 | 
				
			||||||
 | 
					  check_binding_defined 'R run-shell foo_command' ||
 | 
				
			||||||
 | 
					      (echo "Plugin sourcing fails" >&2; FAIL=true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						teardown_helper
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					main() {
 | 
				
			||||||
 | 
					    test_plugin_sourcing
 | 
				
			||||||
 | 
					    exit_value_helper
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					main
 | 
				
			||||||
		Reference in New Issue
	
	Block a user