[bugfix] ensure testrig package only compiled-in when debug enabled (#3185)

* ensure testrig package only compiled-in (including init) when debug enabled

* add code comment to testrig init to indicate WebAssembly compilation
This commit is contained in:
kim 2024-08-09 10:53:29 +00:00 committed by GitHub
parent f77005128a
commit 4a3ece0c6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 19 deletions

View file

@ -0,0 +1,26 @@
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//go:build !debug && !debugenv
package testrig
import "github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
// Start creates and starts a gotosocial testrig server.
// This is only enabled in debug builds, else is nil.
var Start action.GTSAction

View file

@ -15,6 +15,8 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
//go:build debug || debugenv
package testrig package testrig
import ( import (
@ -52,7 +54,8 @@
"github.com/superseriousbusiness/gotosocial/testrig" "github.com/superseriousbusiness/gotosocial/testrig"
) )
// Start creates and starts a gotosocial testrig server // Start creates and starts a gotosocial testrig server.
// This is only enabled in debug builds, else is nil.
var Start action.GTSAction = func(ctx context.Context) error { var Start action.GTSAction = func(ctx context.Context) error {
testrig.InitTestConfig() testrig.InitTestConfig()
testrig.InitTestLog() testrig.InitTestLog()

View file

@ -23,7 +23,6 @@
godebug "runtime/debug" godebug "runtime/debug"
"strings" "strings"
"codeberg.org/gruf/go-debug"
"github.com/spf13/cobra" "github.com/spf13/cobra"
_ "github.com/superseriousbusiness/gotosocial/docs" _ "github.com/superseriousbusiness/gotosocial/docs"
@ -63,11 +62,12 @@ func main() {
rootCmd.AddCommand(serverCommands()) rootCmd.AddCommand(serverCommands())
rootCmd.AddCommand(debugCommands()) rootCmd.AddCommand(debugCommands())
rootCmd.AddCommand(adminCommands()) rootCmd.AddCommand(adminCommands())
if debug.DEBUG {
// only add testrig if debug enabled. // Testrigcmd will only be set when debug is enabled.
rootCmd.AddCommand(testrigCommands()) if testrigCmd := testrigCommands(); testrigCmd != nil {
rootCmd.AddCommand(testrigCmd)
} else if len(os.Args) > 1 && os.Args[1] == "testrig" { } else if len(os.Args) > 1 && os.Args[1] == "testrig" {
log.Fatalln("gotosocial must be built and run with the DEBUG enviroment variable set to enable and access testrig") log.Fatal("gotosocial must be built and run with the DEBUG enviroment variable set to enable and access testrig")
} }
// run // run

View file

@ -23,6 +23,7 @@
) )
func testrigCommands() *cobra.Command { func testrigCommands() *cobra.Command {
if testrig.Start != nil {
testrigCmd := &cobra.Command{ testrigCmd := &cobra.Command{
Use: "testrig", Use: "testrig",
Short: "gotosocial testrig-related tasks", Short: "gotosocial testrig-related tasks",
@ -39,3 +40,5 @@ func testrigCommands() *cobra.Command {
testrigCmd.AddCommand(testrigStartCmd) testrigCmd.AddCommand(testrigStartCmd)
return testrigCmd return testrigCmd
} }
return nil
}

View file

@ -19,6 +19,7 @@
import ( import (
"context" "context"
"fmt"
"os" "os"
"strconv" "strconv"
"time" "time"
@ -34,11 +35,13 @@ func init() {
ctx := context.Background() ctx := context.Background()
// Ensure global ffmpeg WASM pool initialized. // Ensure global ffmpeg WASM pool initialized.
fmt.Println("testrig: precompiling ffmpeg WASM")
if err := ffmpeg.InitFfmpeg(ctx, 1); err != nil { if err := ffmpeg.InitFfmpeg(ctx, 1); err != nil {
panic(err) panic(err)
} }
// Ensure global ffmpeg WASM pool initialized. // Ensure global ffmpeg WASM pool initialized.
fmt.Println("testrig: precompiling ffprobe WASM")
if err := ffmpeg.InitFfprobe(ctx, 1); err != nil { if err := ffmpeg.InitFfprobe(ctx, 1); err != nil {
panic(err) panic(err)
} }