Skip to content

Commit 3f7ad86

Browse files
authored
chore: add a go_test so we can measure some coverage (#405)
1 parent e5d4fa6 commit 3f7ad86

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

oci_go_image/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
22
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
33
load("@container_structure_test//:defs.bzl", "container_structure_test")
4-
load("@rules_go//go:def.bzl", "go_binary", "go_library")
4+
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
55
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
66
load("@rules_pkg//:pkg.bzl", "pkg_tar")
77

@@ -13,6 +13,13 @@ go_library(
1313
deps = ["@com_github_google_go_cmp//cmp"],
1414
)
1515

16+
go_test(
17+
name = "app_test",
18+
size = "small",
19+
srcs = ["main_test.go"],
20+
embed = [":app_lib"],
21+
)
22+
1623
go_binary(
1724
name = "app",
1825
embed = [":app_lib"],

oci_go_image/main.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
package main
1+
package main
22

3-
import (
4-
"fmt"
5-
"github.com/google/go-cmp/cmp"
6-
)
3+
import (
4+
"fmt"
75

8-
func main() {
9-
fmt.Println(cmp.Diff("Hello World", "Hello Go"))
6+
"github.com/google/go-cmp/cmp"
7+
)
8+
9+
func Compare(str1, str2 string) string {
10+
return cmp.Diff(str1, str2)
11+
}
12+
13+
func main() {
14+
fmt.Println(Compare("Hello World", "Hello Go"))
1015
}

oci_go_image/main_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"strings"
5+
"testing"
6+
)
7+
8+
func TestCompare(t *testing.T) {
9+
result := Compare("this", "that")
10+
11+
if !strings.Contains(result, "this") {
12+
t.Error("expected a diff containing 'this' but got", result)
13+
}
14+
}

0 commit comments

Comments
 (0)