github.com/pengwynn/gh@v1.0.1-0.20140118055701-14327ca3942e/Godeps/_workspace/src/code.google.com/p/go-netrc/netrc/netrc_test.go (about)

     1  // Copyright © 2010 Fazlul Shahriar <fshahriar@gmail.com>.
     2  // See LICENSE file for license details.
     3  
     4  package netrc_test
     5  
     6  import (
     7  	. "code.google.com/p/go-netrc/netrc"
     8  	"testing"
     9  )
    10  
    11  var expectedMach = []*Machine{
    12  	&Machine{"mail.google.com", "joe@gmail.com", "somethingSecret", "gmail"},
    13  	&Machine{"ray", "demo", "mypassword", ""},
    14  	&Machine{"", "anonymous", "joe@example.com", ""},
    15  }
    16  var expectedMac = Macros{
    17  	"allput": "put src/*",
    18  }
    19  
    20  func eqMach(a *Machine, b *Machine) bool {
    21  	return a.Name == b.Name &&
    22  		a.Login == b.Login &&
    23  		a.Password == b.Password &&
    24  		a.Account == b.Account
    25  }
    26  
    27  func TestParse(t *testing.T) {
    28  	mach, mac, err := ParseFile("example.netrc")
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  
    33  	for i, e := range expectedMach {
    34  		if !eqMach(e, mach[i]) {
    35  			t.Errorf("bad machine; expected %v, got %v\n", e, mach[i])
    36  		}
    37  	}
    38  
    39  	for k, v := range expectedMac {
    40  		if v != mac[k] {
    41  			t.Errorf("bad macro for %s; expected %s, got %s\n", k, v, mac[k])
    42  		}
    43  	}
    44  }
    45  
    46  func TestFindMachine(t *testing.T) {
    47  	m, err := FindMachine("example.netrc", "ray")
    48  	if err != nil {
    49  		t.Fatal(err)
    50  	}
    51  	if !eqMach(m, expectedMach[1]) {
    52  		t.Errorf("bad machine; expected %v, got %v\n", expectedMach[1], m)
    53  	}
    54  
    55  	m, err = FindMachine("example.netrc", "non.existent")
    56  	if err != nil {
    57  		t.Fatal(err)
    58  	}
    59  	if !eqMach(m, expectedMach[2]) {
    60  		t.Errorf("bad machine; expected %v, got %v\n", expectedMach[2], m)
    61  	}
    62  }