aboutsummaryrefslogtreecommitdiffstats
path: root/octopart_test.go
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2012-08-04 19:28:41 -0700
committerbnewbold <bnewbold@robocracy.org>2012-08-04 19:28:41 -0700
commit24a4873ded5020f99ccb8850c9efda25928b5710 (patch)
treeb4320beee2195d0c6ded407666bf70356000ba98 /octopart_test.go
parente8b87ff1746d7aaa7cd5915e34b3a016b285750f (diff)
downloadbommom-24a4873ded5020f99ccb8850c9efda25928b5710.tar.gz
bommom-24a4873ded5020f99ccb8850c9efda25928b5710.zip
work in progress on octopart fetcher
Diffstat (limited to 'octopart_test.go')
-rw-r--r--octopart_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/octopart_test.go b/octopart_test.go
new file mode 100644
index 0000000..75953ee
--- /dev/null
+++ b/octopart_test.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "testing"
+ "log"
+)
+
+func TestApiCall(t *testing.T) {
+ oc := NewOctopartClient("")
+ result, err := oc.apiCall("parts/search", map[string]string{"q": "ne555", "limit": "2"})
+ if err != nil {
+ t.Errorf("Error with api call: " + err.Error())
+ }
+ log.Println(result["hits"])
+}
+
+func TestGetMarketInfo(t *testing.T) {
+ oc := NewOctopartClient("")
+ log.Println("Running the first time...")
+ result, err := oc.GetMarketInfo([]string{"ti", "atmel", "atmel"}, []string{"ne555", "attiny*", "avrtiny123qqq?"})
+ if err != nil {
+ t.Errorf("Error with api call: " + err.Error())
+ }
+ for i, r := range result {
+ if r == nil {
+ log.Printf("\t%d: %s", i, "nil")
+ } else {
+ log.Printf("\t%d: %s", i, r.(map[string]interface{})["detail_url"])
+ }
+ }
+ log.Println("Running a second time, results should be cached...")
+ result, err = oc.GetMarketInfo([]string{"ti", "atmel", "atmel"}, []string{"ne555", "attiny*", "avrtiny123qqq?"})
+ if err != nil {
+ t.Errorf("Error with api call: " + err.Error())
+ }
+ for i, r := range result {
+ if r == nil {
+ log.Printf("\t%d: %s", i, "nil")
+ } else {
+ log.Printf("\t%d: %s", i, r.(map[string]interface{})["detail_url"])
+ }
+ }
+}
+
+//TODO? TestGetPricing