// Package go-oui provides functions to work with MAC and OUI's
package ouidb

import (
	"fmt"
	"testing"
)

var db OuiDb

func init() {
	db = OuiDb{}
	err := db.Load("oui.txt")
	if err != nil {
		panic(err.Error())
	}
}

func lookup(t *testing.T, mac, org string) {
	address, err := ParseMAC(mac)
	if err != nil {
		t.Fatalf("parse: %s", mac)
	}
	o := db.Lookup(address).Organization
	if o != org {
		t.Fatalf("lookup: input %s, expect %s, got %s", mac, org, o)
	}
	fmt.Printf("    %s => %s\n", mac, o)
}

func TestLookup1(t *testing.T) {
	lookup(t, "60:03:08:a0:ec:a6", "Apple, Inc.")
}

func TestLookup2(t *testing.T) {
	lookup(t, "00:25:9c:42:c2:62", "Cisco-Linksys, LLC")
}

func TestLookup3(t *testing.T) {
	lookup(t, "00:16:e0:3d:f4:4c", "3Com Ltd")
}

// Package go-oui provides functions to work with MAC and OUI's
package ouidb

import (
	"fmt"
	"log"
	"testing"
)

func Test(*testing.T) {
	d := &OuiDb{}
	err := d.Load("oui.txt")

	if err != nil {
		log.Fatal("Error %v", err)
	}

	address, _ := ParseMAC("60:03:08:a0:ec:a6")
	block := d.Lookup(address)

	fmt.Println("bla %v", block)

	address, _ = ParseMAC("00:25:9c:42:c2:62")
	block = d.Lookup(address)

	fmt.Println("Bla %v", block)

	address, _ = ParseMAC("00:16:e0:3d:f4:4c")
	block = d.Lookup(address)

	fmt.Println("Bla %v", block)

}

--- 
+++ 
@@ -3,31 +3,39 @@
 
 import (
 	"fmt"
-	"log"
 	"testing"
 )
 
-func Test(*testing.T) {
-	d := &OuiDb{}
-	err := d.Load("oui.txt")
+var db OuiDb
 
+func init() {
+	db = OuiDb{}
+	err := db.Load("oui.txt")
 	if err != nil {
-		log.Fatal("Error %v", err)
+		panic(err.Error())
 	}
+}
 
-	address, _ := ParseMAC("60:03:08:a0:ec:a6")
-	block := d.Lookup(address)
+func lookup(t *testing.T, mac, org string) {
+	address, err := ParseMAC(mac)
+	if err != nil {
+		t.Fatalf("parse: %s", mac)
+	}
+	o := db.Lookup(address).Organization
+	if o != org {
+		t.Fatalf("lookup: input %s, expect %s, got %s", mac, org, o)
+	}
+	fmt.Printf("    %s => %s\n", mac, o)
+}
 
-	fmt.Println("bla %v", block)
+func TestLookup1(t *testing.T) {
+	lookup(t, "60:03:08:a0:ec:a6", "Apple, Inc.")
+}
 
-	address, _ = ParseMAC("00:25:9c:42:c2:62")
-	block = d.Lookup(address)
+func TestLookup2(t *testing.T) {
+	lookup(t, "00:25:9c:42:c2:62", "Cisco-Linksys, LLC")
+}
 
-	fmt.Println("Bla %v", block)
-
-	address, _ = ParseMAC("00:16:e0:3d:f4:4c")
-	block = d.Lookup(address)
-
-	fmt.Println("Bla %v", block)
-
+func TestLookup3(t *testing.T) {
+	lookup(t, "00:16:e0:3d:f4:4c", "3Com Ltd")
 }
Refactor tests to use testing package errors

Signed-off-by: Claudio Matsuoka <ef7f691d9947ca9adbfeb1538a53a661ec9f041b@gmail.com>
