github.com/bhameyie/otto@v0.2.1-0.20160406174117-16052efa52ec/helper/localaddr/db_cached_test.go (about)

     1  package localaddr
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"testing"
     8  )
     9  
    10  func TestCachedDB(t *testing.T) {
    11  	td, err := ioutil.TempDir("", "localaddr")
    12  	if err != nil {
    13  		t.Fatalf("err: %s", err)
    14  	}
    15  	defer os.RemoveAll(td)
    16  
    17  	db := &CachedDB{
    18  		DB:        &DB{Path: filepath.Join(td, "addr.db")},
    19  		CachePath: filepath.Join(td, "cache"),
    20  	}
    21  
    22  	ip, err := db.IP()
    23  	if err != nil {
    24  		t.Fatalf("err: %s", err)
    25  	}
    26  
    27  	next, err := db.IP()
    28  	if err != nil {
    29  		t.Fatalf("err: %s", err)
    30  	}
    31  	if ip.String() != next.String() {
    32  		t.Fatalf("bad: %s %s", next, ip)
    33  	}
    34  }