aboutsummaryrefslogtreecommitdiffstats
path: root/octopart_test.go
blob: c86ed9be1780053c075abc50001256f59320f59d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main

import (
	"log"
	"os"
	"testing"
)

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 TestGetMarketInfoList(t *testing.T) {
	oc := NewOctopartClient("")
	log.Println("Running the first time...")
	result, err := oc.GetMarketInfoList([]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["detail_url"])
		}
	}
	log.Println("Running a second time, results should be cached...")
	result, err = oc.GetMarketInfoList([]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["detail_url"])
		}
	}
	log.Println("Running in single mode, result should be cached...")
	result_single, err := oc.GetMarketInfo("ti", "ne555")
	if err != nil {
		t.Errorf("Error with api call: " + err.Error())
	}
    if result_single == nil {
        log.Printf("\t%d: %s", 0, "nil")
    } else {
        log.Printf("\t%d: %s", 0, result_single["detail_url"])
    }
}

func TestAttachInfo(t *testing.T) {
	_, b := makeTestBom()
	bm := &BomMeta{}
	oc := NewOctopartClient("")
	oc.AttachMarketInfoBom(b)
	//t.Errorf("unimplemented")
	//DumpBomAsText(bm, b, os.Stdout)
	DumpBomMarketInfo(bm, b, os.Stdout)
    log.Println("Running a second time, results should be cached...")
	oc.AttachMarketInfoBom(b)
	DumpBomMarketInfo(bm, b, os.Stdout)
}