Add tests, fix Makefile
This commit is contained in:
parent
820141f865
commit
ee53efbcd6
2
Makefile
2
Makefile
@ -8,7 +8,7 @@ MAPPER_GEN_FILE := ./api/eiaapi_funcmap.gen.go
|
|||||||
GO_FORMATTER := gofumpt
|
GO_FORMATTER := gofumpt
|
||||||
|
|
||||||
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
|
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
|
||||||
SED_INLINE := $(if $(IS_GNU_SED),-i,-i '')
|
SED_INLINE := $(if $(filter true,$(IS_GNU_SED)),-i,-i '')
|
||||||
|
|
||||||
.PHONY: all schema generate test build install clean
|
.PHONY: all schema generate test build install clean
|
||||||
|
|
||||||
|
@ -90,6 +90,19 @@ func Test_prepMethodArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_getRR(t *testing.T) {
|
func Test_getRR(t *testing.T) {
|
||||||
|
sampleFinalRouteResponse := eiaapi.FinalRouteResponse{
|
||||||
|
Request: &eiaapi.RouteRequest{},
|
||||||
|
Response: &eiaapi.FinalRoute{
|
||||||
|
Description: ptr.To("Annual Energy Outlook"),
|
||||||
|
Id: ptr.To("aeo"),
|
||||||
|
Facets: &[]eiaapi.FacetMetaData{
|
||||||
|
{
|
||||||
|
Description: ptr.To("Future Scenario"),
|
||||||
|
Id: ptr.To("scenario"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
sampleRouteResponse := eiaapi.RouteResponse{
|
sampleRouteResponse := eiaapi.RouteResponse{
|
||||||
Request: &eiaapi.RouteRequest{},
|
Request: &eiaapi.RouteRequest{},
|
||||||
Response: &eiaapi.Routes{
|
Response: &eiaapi.Routes{
|
||||||
@ -112,6 +125,7 @@ func Test_getRR(t *testing.T) {
|
|||||||
args args
|
args args
|
||||||
want eiaapi.RouteResponse
|
want eiaapi.RouteResponse
|
||||||
wantErr bool
|
wantErr bool
|
||||||
|
wantNil bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Extract routes response",
|
name: "Extract routes response",
|
||||||
@ -121,6 +135,15 @@ func Test_getRR(t *testing.T) {
|
|||||||
want: sampleRouteResponse,
|
want: sampleRouteResponse,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Unexpected final route",
|
||||||
|
args: args{
|
||||||
|
json200: reflect.ValueOf(&sampleFinalRouteResponse),
|
||||||
|
},
|
||||||
|
want: eiaapi.RouteResponse{},
|
||||||
|
wantNil: true,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@ -128,6 +151,11 @@ func Test_getRR(t *testing.T) {
|
|||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("getRR() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("getRR() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
} else if (got == nil) != tt.wantNil {
|
||||||
|
t.Error("unexpected nil response")
|
||||||
|
return
|
||||||
|
} else if (got == nil) == tt.wantNil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(*got, tt.want) {
|
if !reflect.DeepEqual(*got, tt.want) {
|
||||||
t.Errorf("getRR() = %v, want %v", got, tt.want)
|
t.Errorf("getRR() = %v, want %v", got, tt.want)
|
||||||
@ -135,3 +163,40 @@ func Test_getRR(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_getParser(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
forMethod string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want reflect.Value
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Get known parser",
|
||||||
|
args: args{forMethod: "GetV2Aeo"},
|
||||||
|
want: reflect.ValueOf(eiaapi.ParseFunctionsMap["ParseGetV2AeoResponse"]),
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Get unknown parser",
|
||||||
|
args: args{forMethod: "GetNonsense"},
|
||||||
|
want: reflect.ValueOf(nil),
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := getParser(tt.args.forMethod)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("getParser() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("getParser() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user