Skip to content

Commit

Permalink
Clean up tests and change revive formatter (#711)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian (Tiedtke) Huckleberry <[email protected]>
  • Loading branch information
adambabik and sourishkrout authored Dec 2, 2024
1 parent 69ba348 commit 4827c98
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ lint:
@gofumpt -d .
@revive \
-config revive.toml \
-formatter stylish \
-formatter friendly \
-exclude integration/subject/... \
./...
@staticcheck ./...
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_terminal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestTerminalCommand_EnvPropagation(t *testing.T) {

// Wait for the prompt before sending the next command.
prompt := "$"
if testutils.IsDockerTestEnv() {
if testutils.IsRunningInDocker() {
prompt = "#"
}
expectContainLines(ctx, t, stdout, []string{prompt})
Expand Down
35 changes: 0 additions & 35 deletions internal/project/projectservice/project_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"

"github.com/stateful/runme/v3/internal/project/projectservice"
Expand Down Expand Up @@ -78,39 +76,6 @@ func TestProjectServiceServer_Load(t *testing.T) {
})
}

func TestProjectServiceServer_Load_ClientConnClosed(t *testing.T) {
t.Parallel()

temp := t.TempDir()
testData := teststub.Setup(t, temp)

lis, stop := testStartProjectServiceServer(t)
t.Cleanup(stop)

clientConn, client := testutils.NewGRPCClientWithT(t, lis, projectv1.NewProjectServiceClient)

req := &projectv1.LoadRequest{
Kind: &projectv1.LoadRequest_File{
File: &projectv1.FileProjectOptions{
Path: testData.ProjectFilePath(),
},
},
}
loadClient, err := client.Load(context.Background(), req)
require.NoError(t, err)

err = clientConn.Close()
require.NoError(t, err)

for {
_, err := loadClient.Recv()
if err != nil {
require.Equal(t, codes.Canceled, status.Code(err))
break
}
}
}

func collectLoadEventTypes(client projectv1.ProjectService_LoadClient) ([]projectv1.LoadEventType, error) {
var eventTypes []projectv1.LoadEventType

Expand Down
4 changes: 2 additions & 2 deletions internal/testutils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package testutils

import "os"

// IsDockerTestEnv returns true if the test is running in a Docker environment.
// IsRunningInDocker returns true if the test is running in a Docker environment.
// Check out the Makefile's "test-docker/run" target where "RUNME_TEST_ENV"
// is set to "docker".
func IsDockerTestEnv() bool {
func IsRunningInDocker() bool {
return os.Getenv("RUNME_TEST_ENV") == "docker"
}
43 changes: 2 additions & 41 deletions main_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,15 @@
package main

import (
"bufio"
"os"
"strings"
"testing"

"github.com/rogpeppe/go-internal/testscript"
"github.com/stateful/runme/v3/internal/testutils"
)

func isDocker() bool {
if _, err := os.Stat("/.dockerenv"); err == nil {
return true
}

paths := []string{"/proc/1/cgroup", "/proc/self/cgroup"}
for _, path := range paths {
file, err := os.Open(path)
if err != nil {
continue
}

scanner := bufio.NewScanner(file)
isDocker := false
for scanner.Scan() {
if strings.Contains(scanner.Text(), "docker") || strings.Contains(scanner.Text(), "kubepods") {
isDocker = true
break
}
}

if err := scanner.Err(); err != nil {
_ = file.Close()
return false
}

_ = file.Close()

if isDocker {
return true
}
}

return false
}

func TestRunmeFilePermissions(t *testing.T) {
if isDocker() {
if testutils.IsRunningInDocker() {
t.Skip("Test skipped when running inside a Docker container")
return
}

testscript.Run(t, testscript.Params{
Expand Down

0 comments on commit 4827c98

Please sign in to comment.