68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
|
package eia
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestNewFacets(t *testing.T) {
|
||
|
type args struct {
|
||
|
facets []*Facet
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want map[string]interface{}
|
||
|
}{
|
||
|
{
|
||
|
name: "Empty facets",
|
||
|
args: args{facets: []*Facet{}},
|
||
|
want: map[string]interface{}{},
|
||
|
},
|
||
|
{
|
||
|
name: "Single facet",
|
||
|
args: args{
|
||
|
facets: []*Facet{
|
||
|
{Name: "seriesId", Data: "Region1"},
|
||
|
},
|
||
|
},
|
||
|
want: map[string]interface{}{
|
||
|
"facets[seriesId][0]": "Region1",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "Multiple facets with unique names",
|
||
|
args: args{
|
||
|
facets: []*Facet{
|
||
|
{Name: "seriesId", Data: "Region1"},
|
||
|
{Name: "scenario", Data: "low-gdp"},
|
||
|
},
|
||
|
},
|
||
|
want: map[string]interface{}{
|
||
|
"facets[seriesId][0]": "Region1",
|
||
|
"facets[scenario][0]": "low-gdp",
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "Multiple facets with duplicate names",
|
||
|
args: args{
|
||
|
facets: []*Facet{
|
||
|
{Name: "scenario", Data: "low-gdp"},
|
||
|
{Name: "scenario", Data: "high-gdp"},
|
||
|
},
|
||
|
},
|
||
|
want: map[string]interface{}{
|
||
|
"facets[scenario][0]": "low-gdp",
|
||
|
"facets[scenario][1]": "high-gdp",
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := NewFacets(tt.args.facets...); !reflect.DeepEqual(*got, tt.want) {
|
||
|
t.Errorf("NewFacets() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|