mirror of
1
Fork 0

[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
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//go:build debug || debugenv
package testrig
import (
@ -52,7 +54,8 @@ import (
"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 {
testrig.InitTestConfig()
testrig.InitTestLog()

View File

@ -23,7 +23,6 @@ import (
godebug "runtime/debug"
"strings"
"codeberg.org/gruf/go-debug"
"github.com/spf13/cobra"
_ "github.com/superseriousbusiness/gotosocial/docs"
@ -63,11 +62,12 @@ func main() {
rootCmd.AddCommand(serverCommands())
rootCmd.AddCommand(debugCommands())
rootCmd.AddCommand(adminCommands())
if debug.DEBUG {
// only add testrig if debug enabled.
rootCmd.AddCommand(testrigCommands())
// Testrigcmd will only be set when debug is enabled.
if testrigCmd := testrigCommands(); testrigCmd != nil {
rootCmd.AddCommand(testrigCmd)
} 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

View File

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

View File

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