-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend the
patch
package used by registry apply
to support lists …
…returned by `registry get` (#939)
- Loading branch information
Showing
5 changed files
with
687 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2023 Google LLC. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package patch | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/apigee/registry/pkg/connection" | ||
"github.com/apigee/registry/rpc" | ||
"github.com/apigee/registry/server/registry/names" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func TestArtifactLists(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
root string | ||
}{ | ||
{ | ||
desc: "artifacts", | ||
root: "testdata/lists", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.desc, func(t *testing.T) { | ||
ctx := context.Background() | ||
adminClient, err := connection.NewAdminClient(ctx) | ||
if err != nil { | ||
t.Fatalf("Setup: failed to create client: %+v", err) | ||
} | ||
project := names.Project{ProjectID: "patch-lists-test"} | ||
if err = adminClient.DeleteProject(ctx, &rpc.DeleteProjectRequest{ | ||
Name: project.String(), | ||
Force: true, | ||
}); err != nil && status.Code(err) != codes.NotFound { | ||
t.Errorf("Setup: failed to delete test project: %s", err) | ||
} | ||
if _, err := adminClient.CreateProject(ctx, &rpc.CreateProjectRequest{ | ||
ProjectId: project.ProjectID, | ||
Project: &rpc.Project{}, | ||
}); err != nil { | ||
t.Fatalf("Setup: Failed to create test project: %s", err) | ||
} | ||
t.Cleanup(func() { | ||
if err := adminClient.DeleteProject(ctx, &rpc.DeleteProjectRequest{ | ||
Name: project.String(), | ||
Force: true, | ||
}); err != nil { | ||
t.Logf("Cleanup: Failed to delete test project: %s", err) | ||
} | ||
adminClient.Close() | ||
}) | ||
|
||
// set the configured registry.project to the test project | ||
config, err := connection.ActiveConfig() | ||
if err != nil { | ||
t.Fatalf("Setup: Failed to get registry configuration: %s", err) | ||
} | ||
config.Project = project.ProjectID | ||
connection.SetConfig(config) | ||
|
||
registryClient, err := connection.NewRegistryClient(ctx) | ||
if err != nil { | ||
t.Fatalf("Setup: Failed to create registry client: %s", err) | ||
} | ||
defer registryClient.Close() | ||
|
||
if err := Apply(ctx, registryClient, test.root, project.String()+"/locations/global", true, 10); err != nil { | ||
t.Fatalf("Apply() returned error: %s", err) | ||
} | ||
|
||
artifacts := []string{ | ||
"apihub-display-settings", | ||
"apihub-lifecycle", | ||
"apihub-lint-errors", | ||
"apihub-lint-summary", | ||
"apihub-lint-warnings", | ||
"apihub-styleguide", | ||
"apihub-taxonomies", | ||
} | ||
for _, a := range artifacts { | ||
_, err := registryClient.GetArtifact(ctx, &rpc.GetArtifactRequest{ | ||
Name: project.Artifact(a).String(), | ||
}) | ||
if status.Code(err) == codes.NotFound { | ||
t.Fatalf("Expected artifact doesn't exist: %s", err) | ||
} else if err != nil { | ||
t.Fatalf("Failed to verify artifact existence: %s", err) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.