Add route tests
This commit is contained in:
@ -1,8 +1,13 @@
|
||||
package eia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
eiaapi "gitea.libretechconsulting.com/50W/eia-api-go/api"
|
||||
)
|
||||
|
||||
func TestGetRoutes(t *testing.T) {
|
||||
@ -38,3 +43,95 @@ func TestGetRoutes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_prepMethodArgs(t *testing.T) {
|
||||
client, _ := eiaapi.NewClient("test.test")
|
||||
type args struct {
|
||||
method reflect.Value
|
||||
name string
|
||||
subs *MethodSubs
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []reflect.Value
|
||||
}{
|
||||
{
|
||||
name: "Test substitute GetV2AeoRoute1FacetFacetId params",
|
||||
args: args{
|
||||
name: "GetV2AeoRoute1FacetFacetId",
|
||||
method: reflect.ValueOf(
|
||||
client.GetV2AeoRoute1FacetFacetId,
|
||||
),
|
||||
subs: &MethodSubs{
|
||||
TypedParams: map[reflect.Type]reflect.Value{
|
||||
reflect.TypeOf((*context.Context)(nil)).Elem(): reflect.ValueOf(context.TODO()),
|
||||
},
|
||||
StrTypedParams: map[string]reflect.Value{
|
||||
"FacetId": reflect.ValueOf(eiaapi.FacetId("seriesId")),
|
||||
"Route1": reflect.ValueOf(eiaapi.Route1("2023")),
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []reflect.Value{
|
||||
reflect.ValueOf(context.TODO()),
|
||||
reflect.ValueOf(eiaapi.Route1("2023")),
|
||||
reflect.ValueOf(eiaapi.FacetId("seriesId")),
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := prepMethodArgs(tt.args.method, tt.args.name, tt.args.subs); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("prepMethodArgs() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getRR(t *testing.T) {
|
||||
sampleRouteResponse := eiaapi.RouteResponse{
|
||||
Request: &eiaapi.RouteRequest{},
|
||||
Response: &eiaapi.Routes{
|
||||
Description: ptr.To("Annual Energy Outlook"),
|
||||
Id: ptr.To("aeo"),
|
||||
Name: ptr.To("aeo"),
|
||||
Routes: ptr.To([]eiaapi.Routes{
|
||||
{
|
||||
Id: ptr.To("2023"),
|
||||
Name: ptr.To("2023"),
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
type args struct {
|
||||
json200 reflect.Value
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want eiaapi.RouteResponse
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Extract routes response",
|
||||
args: args{
|
||||
json200: reflect.ValueOf(&sampleRouteResponse),
|
||||
},
|
||||
want: sampleRouteResponse,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := getRR(tt.args.json200)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getRR() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(*got, tt.want) {
|
||||
t.Errorf("getRR() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user