From 9bdfbe6f2710613fdcedeb2c43b066783e4703b0 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 1 Dec 2023 15:36:01 -0800 Subject: [PATCH 1/2] Add github actions to dataapiv2 --- .github/workflows/unit-test-data-api-v2.yaml | 27 +++++++++++++++++++ tools/data-api/GNUmakefile | 3 +++ .../internal/endpoints/v1/mappings.go | 2 +- .../internal/repositories/services_test.go | 27 +++++++++++++++++++ .../internal/repositories/validation.go | 2 +- 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/unit-test-data-api-v2.yaml create mode 100644 tools/data-api/internal/repositories/services_test.go diff --git a/.github/workflows/unit-test-data-api-v2.yaml b/.github/workflows/unit-test-data-api-v2.yaml new file mode 100644 index 00000000000..a06abfc8917 --- /dev/null +++ b/.github/workflows/unit-test-data-api-v2.yaml @@ -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 diff --git a/tools/data-api/GNUmakefile b/tools/data-api/GNUmakefile index 0ef286588ed..5f8e7f21637 100644 --- a/tools/data-api/GNUmakefile +++ b/tools/data-api/GNUmakefile @@ -9,4 +9,7 @@ fmt: run: build ./data-api serve +test: build + go test -v ./... + .PHONY: build fmt run diff --git a/tools/data-api/internal/endpoints/v1/mappings.go b/tools/data-api/internal/endpoints/v1/mappings.go index 5859f69884e..5fefae16491 100644 --- a/tools/data-api/internal/endpoints/v1/mappings.go +++ b/tools/data-api/internal/endpoints/v1/mappings.go @@ -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 diff --git a/tools/data-api/internal/repositories/services_test.go b/tools/data-api/internal/repositories/services_test.go new file mode 100644 index 00000000000..3bcd03858e5 --- /dev/null +++ b/tools/data-api/internal/repositories/services_test.go @@ -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_Graph(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()) + } +} diff --git a/tools/data-api/internal/repositories/validation.go b/tools/data-api/internal/repositories/validation.go index 815bc00cdac..91dbc0dce62 100644 --- a/tools/data-api/internal/repositories/validation.go +++ b/tools/data-api/internal/repositories/validation.go @@ -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 := "" From 4dc40824122eed79abfd11217135a7a99be96fd1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 5 Dec 2023 10:34:25 -0800 Subject: [PATCH 2/2] Update tools/data-api/internal/repositories/services_test.go Co-authored-by: Tom Harvey --- tools/data-api/internal/repositories/services_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/data-api/internal/repositories/services_test.go b/tools/data-api/internal/repositories/services_test.go index 3bcd03858e5..7fa5b3476c2 100644 --- a/tools/data-api/internal/repositories/services_test.go +++ b/tools/data-api/internal/repositories/services_test.go @@ -15,7 +15,7 @@ func TestServices_ResourceManager(t *testing.T) { } } -func TestServices_Graph(t *testing.T) { +func TestServices_MicrosoftGraph(t *testing.T) { repo, err := NewServicesRepository("../../../../api-definitions/", MicrosoftGraphV1StableServiceType, nil) if err != nil { t.Fatalf(err.Error())