github.com/jerryclinesmith/packer@v0.3.7/communicator/ssh/password_test.go (about)

     1  package ssh
     2  
     3  import (
     4  	"code.google.com/p/go.crypto/ssh"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestPassword_Impl(t *testing.T) {
    10  	var raw interface{}
    11  	raw = Password("foo")
    12  	if _, ok := raw.(ssh.ClientPassword); !ok {
    13  		t.Fatal("Password must implement ClientPassword")
    14  	}
    15  }
    16  
    17  func TestPasswordPassword(t *testing.T) {
    18  	p := Password("foo")
    19  	result, err := p.Password("user")
    20  	if err != nil {
    21  		t.Fatalf("err not nil: %s", err)
    22  	}
    23  
    24  	if result != "foo" {
    25  		t.Fatalf("invalid password: %s", result)
    26  	}
    27  }
    28  
    29  func TestPasswordKeyboardInteractive_Impl(t *testing.T) {
    30  	var raw interface{}
    31  	raw = PasswordKeyboardInteractive("foo")
    32  	if _, ok := raw.(ssh.ClientKeyboardInteractive); !ok {
    33  		t.Fatal("PasswordKeyboardInteractive must implement ClientKeyboardInteractive")
    34  	}
    35  }
    36  
    37  func TestPasswordKeybardInteractive_Challenge(t *testing.T) {
    38  	p := PasswordKeyboardInteractive("foo")
    39  	result, err := p.Challenge("foo", "bar", []string{"one", "two"}, nil)
    40  	if err != nil {
    41  		t.Fatalf("err not nil: %s", err)
    42  	}
    43  
    44  	if !reflect.DeepEqual(result, []string{"foo", "foo"}) {
    45  		t.Fatalf("invalid password: %#v", result)
    46  	}
    47  }