mirror of
				https://github.com/appleboy/drone-ssh.git
				synced 2025-10-29 00:51:15 +08:00 
			
		
		
		
	test: Add escapeArg testing
This commit is contained in:
		
							parent
							
								
									7f4cb1c1d0
								
							
						
					
					
						commit
						d657910d02
					
				| @ -273,3 +273,36 @@ func TestSyncMode(t *testing.T) { | |||||||
| 	err := plugin.Exec() | 	err := plugin.Exec() | ||||||
| 	assert.Nil(t, err) | 	assert.Nil(t, err) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func Test_escapeArg(t *testing.T) { | ||||||
|  | 	type args struct { | ||||||
|  | 		arg string | ||||||
|  | 	} | ||||||
|  | 	tests := []struct { | ||||||
|  | 		name string | ||||||
|  | 		args args | ||||||
|  | 		want string | ||||||
|  | 	}{ | ||||||
|  | 		{ | ||||||
|  | 			name: "escape nothing", | ||||||
|  | 			args: args{ | ||||||
|  | 				arg: "Hi I am appleboy", | ||||||
|  | 			}, | ||||||
|  | 			want: `'Hi I am appleboy'`, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			name: "escape single quote", | ||||||
|  | 			args: args{ | ||||||
|  | 				arg: "Hi I am 'appleboy'", | ||||||
|  | 			}, | ||||||
|  | 			want: `'Hi I am '\''appleboy'\'''`, | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | 	for _, tt := range tests { | ||||||
|  | 		t.Run(tt.name, func(t *testing.T) { | ||||||
|  | 			if got := escapeArg(tt.args.arg); got != tt.want { | ||||||
|  | 				t.Errorf("escapeArg() = %v, want %v", got, tt.want) | ||||||
|  | 			} | ||||||
|  | 		}) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Bo-Yi Wu
						Bo-Yi Wu