Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: generate Go boilerplate to disable logging in tests. #1889

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cloud/deployment/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package deployment_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions cloud/drift/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package drift_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Terramate GmbH
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package cloud_test
Expand Down
10 changes: 10 additions & 0 deletions cloud/preview/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package preview_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Terramate GmbH
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package stack_test
Expand Down
10 changes: 10 additions & 0 deletions cloud/testserver/cloudstore/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package cloudstore_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions cloud/testserver/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package testserver_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
5 changes: 0 additions & 5 deletions cmd/terramate/cli/cliconfig/cliconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/cmd/terramate/cli/cliconfig"
"github.com/terramate-io/terramate/errors"
"github.com/terramate-io/terramate/hcl"
Expand Down Expand Up @@ -158,7 +157,3 @@ func TestLoad(t *testing.T) {
})
}
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 Terramate GmbH
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package terramate_test
package cliconfig_test

import "github.com/rs/zerolog"

Expand Down
10 changes: 10 additions & 0 deletions cmd/terramate/cli/github/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package github_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions cmd/terramate/cli/gitlab/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package gitlab_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions cmd/terramate/cli/out/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package out_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
5 changes: 0 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/config"
"github.com/terramate-io/terramate/errors"
"github.com/terramate-io/terramate/project"
Expand Down Expand Up @@ -333,7 +332,3 @@ func TestConfigSkipdir(t *testing.T) {
func isStack(root *config.Root, dir string) bool {
return config.IsStack(root, filepath.Join(root.HostDir(), dir))
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions config/filter/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package filter_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions config/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package config_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions e2etests/cloud/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package cloud_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Terramate GmbH
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package core_test
Expand Down
10 changes: 10 additions & 0 deletions errors/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package errors_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions event/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package event_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
5 changes: 0 additions & 5 deletions fs/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/fs"
"github.com/terramate-io/terramate/test"
"github.com/terramate-io/terramate/test/sandbox"
Expand Down Expand Up @@ -56,7 +55,3 @@ func TestCopyIfAllFilesAreFilteredDirIsNotCreated(t *testing.T) {
}
}
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions fs/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package fs_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
5 changes: 0 additions & 5 deletions generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"testing"

"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/config"
"github.com/terramate-io/terramate/errors"
"github.com/terramate-io/terramate/generate"
Expand Down Expand Up @@ -1292,7 +1291,3 @@ func assertEqualStringList(t *testing.T, got []string, want []string) {
t.Fatalf("got %v != want %v", got, want)
}
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
5 changes: 0 additions & 5 deletions generate/genfile/genfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/config"
"github.com/terramate-io/terramate/errors"
"github.com/terramate-io/terramate/generate/genfile"
Expand Down Expand Up @@ -1020,7 +1019,3 @@ func testGenfile(t *testing.T, tcase testcase) {
}
})
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions generate/genfile/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package genfile_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
5 changes: 0 additions & 5 deletions generate/genhcl/genhcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/config"
"github.com/terramate-io/terramate/errors"
"github.com/terramate-io/terramate/generate/genhcl"
Expand Down Expand Up @@ -1956,7 +1955,3 @@ func assertHCLEquals(t *testing.T, got string, want string) {
t.Fatalf("diff:\n%s", diff)
}
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions generate/genhcl/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package genhcl_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions generate/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package generate_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
38 changes: 38 additions & 0 deletions generate_golang.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

globals {
# you can enable this only in the stack you are debugging the tests.
enable_test_logging = false

is_go_package = tm_anytrue([
tm_contains(terramate.stack.tags, "golang"),
tm_contains(terramate.stack.tags, "e2etests"),
])
has_test_files = tm_length(tm_fileset(".", "*_test.go")) > 0
}

generate_file "loglevel_disable_test.go" {
condition = !global.enable_test_logging && global.is_go_package && global.has_test_files
lets {
special_cases = {
"ls" = "tmls"
"/" = "terramate"
}
is_main = tm_can(tm_file("main.go"))
basename = terramate.stack.path.basename
pkgname = let.is_main ? "main" : tm_try(let.special_cases[let.basename], let.basename)
}
content = <<-EOF
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0
package ${let.pkgname}_test
import "github.com/rs/zerolog"
func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
EOF
}
File renamed without changes.
5 changes: 1 addition & 4 deletions generate_preview.tm → generate_mock_preview.tm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
// This file is required by the "preview" script.

generate_hcl "_test_mock.tf" {
condition = tm_anytrue([
tm_contains(terramate.stack.tags, "golang"),
tm_contains(terramate.stack.tags, "e2etests"),
])
condition = global.is_go_package
lets {
name = tm_ternary(terramate.stack.path.basename == "/", "terramate", terramate.stack.path.basename)
}
Expand Down
5 changes: 0 additions & 5 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/madlambda/spells/assert"
"github.com/rs/zerolog"
"github.com/terramate-io/terramate/git"
"github.com/terramate-io/terramate/test"
"github.com/terramate-io/terramate/test/sandbox"
Expand Down Expand Up @@ -567,7 +566,3 @@ func assertEqualRemotes(t *testing.T, got []git.Remote, want []git.Remote) {
)
}
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
10 changes: 10 additions & 0 deletions git/loglevel_disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

package git_test

import "github.com/rs/zerolog"

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
Loading
Loading