Skip to content

Commit

Permalink
Align e2e orchestration project structure with bazel gazelle.
Browse files Browse the repository at this point in the history
- BUILD files under the orchestration directory should not have
  contradictions with `bazel run //:gazelle`.
  • Loading branch information
ser-io committed Oct 14, 2024
1 parent c22ea98 commit cdbeb9b
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 534 deletions.
8 changes: 7 additions & 1 deletion e2etests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@

load("@bazel_gazelle//:def.bzl", "gazelle")

gazelle(name = "gazelle")
GO_PREFIX = "github.com/google/android-cuttlefish/e2etests"

gazelle(
name = "gazelle",
external = "external",
prefix = GO_PREFIX,
)
17 changes: 5 additions & 12 deletions e2etests/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# e2e tests

## Golang tests

e2e tests are meant to be run with `bazel`, i.e `bazel test orchestration/...`. However,
the tests are still buildable with the `go` tool, i.e `go test ./...` should not present
any compilation erros, the execution should fail due missing data dependencies.

Adding a new dependency requires updating `go.mod` as well as `bazel` relevant files.
## Orchestration tests

```
# 1. Update go.mod.
go get <dependency> # i.e `go get github.com/google/go-cmp/cmp`
# 2. Update deps.bzl
bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
# 3. Update BUILD files.
bazel run //:gazelle
```

```
bazel test --local_test_jobs=1 orchestration/...
```
24 changes: 10 additions & 14 deletions e2etests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,24 @@ http_archive(
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

############################################################
# Define your own dependencies here using go_repository.
# Else, dependencies declared by rules_go/gazelle will be used.
# The first declaration of an external repository "wins".
############################################################

load("//:deps.bzl", "go_dependencies")

# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()

go_rules_dependencies()

go_register_toolchains(version = "1.20.7")

gazelle_dependencies()
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

load("//:go_repositories.bzl", "repos")

# gazelle:repository_macro go_repositories.bzl%repos
repos()

gazelle_dependencies()

local_repository(
name = "images",
path = "..",
Expand Down
45 changes: 0 additions & 45 deletions e2etests/go.mod

This file was deleted.

308 changes: 0 additions & 308 deletions e2etests/go.sum

This file was deleted.

2 changes: 1 addition & 1 deletion e2etests/deps.bzl → e2etests/go_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@bazel_gazelle//:deps.bzl", "go_repository")

def go_dependencies():
def repos():
go_repository(
name = "co_honnef_go_tools",
importpath = "honnef.co/go/tools",
Expand Down
106 changes: 0 additions & 106 deletions e2etests/orchestration/BUILD.bazel

This file was deleted.

36 changes: 36 additions & 0 deletions e2etests/orchestration/artifacts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2024 The Android Open Source Project
#
# 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.

load("def.bzl", "aosp_artifact")

sh_binary(
name = "fetch_aosp_artifact",
srcs = ["fetch_aosp_artifact.sh"],
)

aosp_artifact(
name = "cvd_host_package",
artifact_name = "cvd-host_package.tar.gz",
build_id = "12432601",
build_target = "aosp_cf_x86_64_phone-trunk_staging-userdebug",
out_name = "cvd-host_package.tar.gz",
)

aosp_artifact(
name = "images_zip",
artifact_name = "aosp_cf_x86_64_phone-img-12432601.zip",
build_id = "12432601",
build_target = "aosp_cf_x86_64_phone-trunk_staging-userdebug",
out_name = "images.zip",
)
22 changes: 22 additions & 0 deletions e2etests/orchestration/artifacts/def.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2024 The Android Open Source Project
#
# 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.

def aosp_artifact(name, build_id, build_target, artifact_name, out_name):
native.genrule(
name = name,
outs = [out_name],
visibility = ["//visibility:public"],
cmd = "$(location :fetch_aosp_artifact) -b "+build_id+" -t "+build_target+" -a "+artifact_name+" -o $@",
tools = [":fetch_aosp_artifact"],
)
29 changes: 29 additions & 0 deletions e2etests/orchestration/common/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2024 The Android Open Source Project
#
# 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.

load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "common",
srcs = ["common.go"],
importpath = "github.com/google/android-cuttlefish/e2etests/orchestration/common",
visibility = ["//visibility:public"],
deps = [
"@com_github_docker_docker//api/types",
"@com_github_docker_docker//api/types/container",
"@com_github_docker_docker//client",
"@com_github_docker_go_connections//nat",
"@com_github_google_cloud_android_orchestration//pkg/client",
],
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e2etesting
package common

import (
"archive/zip"
Expand Down Expand Up @@ -79,7 +79,7 @@ func NewDockerHelper() (*DockerHelper, error) {
}

func (h *DockerHelper) LoadImage() (string, error) {
imgFile, err := os.Open("../external/images/docker/orchestration-image.tar")
imgFile, err := os.Open("../../external/images/docker/orchestration-image.tar")
if err != nil {
return "", err
}
Expand Down
31 changes: 31 additions & 0 deletions e2etests/orchestration/create_from_images_zip_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2024 The Android Open Source Project
#
# 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.

load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "create_from_images_zip_test_test",
srcs = ["main_test.go"],
data = [
"//orchestration/artifacts:cvd_host_package",
"//orchestration/artifacts:images_zip",
"@images//docker:orchestration_image_tar",
],
deps = [
"//orchestration/common",
"@com_github_google_android_cuttlefish_frontend_src_liboperator//api/v1:api",
"@com_github_google_cloud_android_orchestration//pkg/client",
"@com_github_google_go_cmp//cmp",
],
)
Loading

0 comments on commit cdbeb9b

Please sign in to comment.