Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #10 handle no newline issue #11

Merged
merged 1 commit into from
Nov 5, 2020
Merged

Conversation

chinglinwen
Copy link
Contributor

test

func TestHost(t *testing.T) {
	hostsfile := "/tmp/hosts.txt"

	data := []byte("127.0.0.1 localhost")
	err := ioutil.WriteFile(hostsfile, data, 0644)
	if err != nil {
		t.Error("prepare test hosts file err", err)
		return
	}

	hosts, err = txeh.NewHosts(&txeh.HostsConfig{
		ReadFilePath:  hostsfile,
		WriteFilePath: hostsfile,
	})
	if err != nil {
		t.Error("create hosts err", err)
		return
	}
	spew.Dump("hosts: ", hosts)
	t.Logf("init: %q\n", hosts.RenderHostsFile())
}

origin

=== RUN   TestHost
(string) (len=7) "hosts: "
(*txeh.Hosts)(0xc00009a4e0)({
 Mutex: (sync.Mutex) {
  state: (int32) 0,
  sema: (uint32) 0
 },
 HostsConfig: (*txeh.HostsConfig)(0xc0000ba180)({
  ReadFilePath: (string) (len=14) "/tmp/hosts.txt",
  WriteFilePath: (string) (len=14) "/tmp/hosts.txt"
 }),
 hostFileLines: (txeh.HostFileLines) {
 }
})
    TestHost: hosts_test.go:37: init: ""
    TestHost: hosts_test.go:50: after add:  1.1.1.1          demo.com
        
    TestHost: hosts_test.go:61: after remove: 

after fixes

=== RUN   TestHost
(string) (len=7) "hosts: "
(*txeh.Hosts)(0xc00010c480)({
 Mutex: (sync.Mutex) {
  state: (int32) 0,
  sema: (uint32) 0
 },
 HostsConfig: (*txeh.HostsConfig)(0xc000122180)({
  ReadFilePath: (string) (len=14) "/tmp/hosts.txt",
  WriteFilePath: (string) (len=14) "/tmp/hosts.txt"
 }),
 hostFileLines: (txeh.HostFileLines) (len=1 cap=1) {
  (txeh.HostFileLine) {
   OriginalLineNum: (int) 0,
   LineType: (int) 30,
   Address: (string) (len=9) "127.0.0.1",
   Parts: ([]string) (len=2 cap=2) {
    (string) (len=9) "127.0.0.1",
    (string) (len=9) "localhost"
   },
   Hostnames: ([]string) (len=1 cap=1) {
    (string) (len=9) "localhost"
   },
   Raw: (string) (len=19) "127.0.0.1 localhost",
   Trimed: (string) (len=19) "127.0.0.1 localhost",
   Comment: (string) ""
  }
 }
})
    TestHost: hosts_test.go:37: init: "127.0.0.1        localhost\n"
    TestHost: hosts_test.go:50: after add:  127.0.0.1        localhost
        1.1.1.1          demo.com
        
    TestHost: hosts_test.go:61: after remove:  127.0.0.1        localhost

Signed-off-by: chinglinwen <chinglinwen@gmail.com>
@cjimti cjimti merged commit 09e2953 into txn2:master Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants