Skip to content

Commit

Permalink
build: allow go test ./... to run without errors
Browse files Browse the repository at this point in the history
Ensure `go test ./...` runs without errors out-of-the-box.
To this end, we guard the acceptance tests behind a skip tag because
they require a special setup and are not meant to be run as regular
unit tests. We also add stub packages for the linter tests.
  • Loading branch information
oncilla committed Aug 7, 2023
1 parent 49b3f90 commit 568680c
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 1 deletion.
5 changes: 5 additions & 0 deletions acceptance/topo_cs_reload/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/http"
"os"
"os/exec"
"strings"
"testing"
"time"

Expand All @@ -42,6 +43,10 @@ var (
)

func TestPSTopoReload(t *testing.T) {
if !strings.HasSuffix(os.Getenv("TEST_TARGET"), "go_default_test") {
t.Skip("This test only runs as bazel unit test")
}

// BUG(matzf): teardown is not called when setup fails. Rewrite with T.Cleanup and T.Tempdir
s := setupTest(t)
defer s.teardownTest(t)
Expand Down
5 changes: 5 additions & 0 deletions acceptance/topo_daemon_reload/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"os"
"os/exec"
"strings"
"testing"
"time"

Expand All @@ -31,6 +32,10 @@ import (
)

func TestSDTopoReload(t *testing.T) {
if !strings.HasSuffix(os.Getenv("TEST_TARGET"), "go_default_test") {
t.Skip("This test only runs as bazel unit test")
}

defer teardownTest(t)
setupTest(t)

Expand Down
20 changes: 20 additions & 0 deletions tools/lint/logctxcheck/testdata/src/fake/lib/slog/slog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 Anapaya Systems
//
// 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 slog is a stub for testing
package slog

func Debug(string, ...any) {}
func Info(string, ...any) {}
func Error(string, ...any) {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 Anapaya Systems
//
// 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 log is a stub for the actual log package. It allows the logctxcheck
// analyzer tests to run.
package log

import "context"

func Debug(string, ...any) {}
func Info(string, ...any) {}
func Error(string, ...any) {}
func New(...any) Logger { return nil }
func FromCtx(context.Context) Logger { return nil }
func Root() Logger { return nil }

type Logger interface {
Debug(string, ...any)
Info(string, ...any)
Error(string, ...any)
}
19 changes: 19 additions & 0 deletions tools/lint/serrorscheck/testdata/src/fake/serrors/serrors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 Anapaya Systems
//
// 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 serrors is a stub for testing
package serrors

func New(string, ...any) error { return nil }
func Wrap(error, error, ...any) error { return nil }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 Anapaya Systems
//
// 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 serrors is a stub for the actual serrors package. It allows the
// serrorscheck analyzer tests to run.
package serrors

func New(string, ...any) error { return nil }
func Wrap(error, error, ...any) error { return nil }
func WrapStr(error, string, ...any) error { return nil }
func WithCtx(error, ...any) error { return nil }

0 comments on commit 568680c

Please sign in to comment.