github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/not-internal/auth/netrc_test.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package auth 6 7 import ( 8 "reflect" 9 "testing" 10 ) 11 12 var testNetrc = ` 13 machine incomplete 14 password none 15 16 machine api.github.com 17 login user 18 password pwd 19 20 machine incomlete.host 21 login justlogin 22 23 machine test.host 24 login user2 25 password pwd2 26 27 machine oneline login user3 password pwd3 28 29 machine ignore.host macdef ignore 30 login nobody 31 password nothing 32 33 machine hasmacro.too macdef ignore-next-lines login user4 password pwd4 34 login nobody 35 password nothing 36 37 default 38 login anonymous 39 password gopher@golang.org 40 41 machine after.default 42 login oops 43 password too-late-in-file 44 ` 45 46 func TestParseNetrc(t *testing.T) { 47 lines := parseNetrc(testNetrc) 48 want := []netrcLine{ 49 {"api.github.com", "user", "pwd"}, 50 {"test.host", "user2", "pwd2"}, 51 {"oneline", "user3", "pwd3"}, 52 {"hasmacro.too", "user4", "pwd4"}, 53 } 54 55 if !reflect.DeepEqual(lines, want) { 56 t.Errorf("parseNetrc:\nhave %q\nwant %q", lines, want) 57 } 58 }