Skip to content

Commit

Permalink
Merge pull request #3428 from hashicorp/data-api-v2-github-action
Browse files Browse the repository at this point in the history
dataapiv2 - Add github actions to dataapiv2
  • Loading branch information
mbfrahry authored Dec 5, 2023
2 parents 6a6ec2d + 4dc4082 commit baaf7c5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/unit-test-data-api-v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Verify Data API V2 API Definitions Can be Mapped
on:
pull_request:
types: ['opened', 'synchronize']
paths:
- '.github/workflows/**'
- 'tools/data-api/**'

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: '1.21.3'

- name: run unit tests
run: |
cd ./tools/data-api
make test
3 changes: 3 additions & 0 deletions tools/data-api/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ fmt:
run: build
./data-api serve

test: build
go test -v ./...

.PHONY: build fmt run
2 changes: 1 addition & 1 deletion tools/data-api/internal/endpoints/v1/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func mapDateFormat(input *repositories.DateFormat) (*models.DateFormat, error) {
if v, ok := mappings[*input]; ok {
return &v, nil
}
return nil, fmt.Errorf("unmapped date format %q", input)
return nil, fmt.Errorf("unmapped date format %+v", input)
}

return nil, nil
Expand Down
27 changes: 27 additions & 0 deletions tools/data-api/internal/repositories/services_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package repositories

import (
"testing"
)

func TestServices_ResourceManager(t *testing.T) {
repo, err := NewServicesRepository("../../../../api-definitions/", ResourceManagerServiceType, nil)
if err != nil {
t.Fatalf(err.Error())
}

if _, err := repo.GetAll(ResourceManagerServiceType); err != nil {
t.Fatalf(err.Error())
}
}

func TestServices_MicrosoftGraph(t *testing.T) {
repo, err := NewServicesRepository("../../../../api-definitions/", MicrosoftGraphV1StableServiceType, nil)
if err != nil {
t.Fatalf(err.Error())
}

if _, err := repo.GetAll(MicrosoftGraphV1StableServiceType); err != nil {
t.Fatalf(err.Error())
}
}
2 changes: 1 addition & 1 deletion tools/data-api/internal/repositories/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func validateModels(input map[string]ModelDetails, constants map[string]Constant

parentModel, ok := input[*modelDetail.ParentTypeName]
if !ok {
return fmt.Errorf("model %q: discriminated parent type model %q not found", *modelDetail.ParentTypeName)
return fmt.Errorf("model %q: discriminated parent type model %q not found", modelName, *modelDetail.ParentTypeName)
}

typeHintIn := ""
Expand Down

0 comments on commit baaf7c5

Please sign in to comment.