package commerce

import (
	"testing"
)

func TestJSONList(t *testing.T) {
	items := jsonList(JSONRaw(`[{"label":"Ubuntu","value":1}]`))
	if len(items) != 1 {
		t.Fatalf("expected one item, got %d", len(items))
	}
}

func TestJSONListFallback(t *testing.T) {
	items := jsonList(JSONRaw(`{"not":"a-list"}`))
	if len(items) != 0 {
		t.Fatalf("expected empty list, got %d", len(items))
	}
}

func TestJSONObject(t *testing.T) {
	item := jsonObject(JSONRaw(`{"hostname":"web01"}`))
	if item["hostname"] != "web01" {
		t.Fatalf("unexpected json object: %#v", item)
	}
}
