mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-22 10:12:11 +00:00
[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:
parent
f77005128a
commit
4a3ece0c6c
26
cmd/gotosocial/action/testrig/no_testrig.go
Normal file
26
cmd/gotosocial/action/testrig/no_testrig.go
Normal 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
|
|
@ -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 @@
|
|||
"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()
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
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
|
||||
|
|
|
@ -23,19 +23,22 @@
|
|||
)
|
||||
|
||||
func testrigCommands() *cobra.Command {
|
||||
testrigCmd := &cobra.Command{
|
||||
Use: "testrig",
|
||||
Short: "gotosocial testrig-related tasks",
|
||||
}
|
||||
if testrig.Start != nil {
|
||||
testrigCmd := &cobra.Command{
|
||||
Use: "testrig",
|
||||
Short: "gotosocial testrig-related tasks",
|
||||
}
|
||||
|
||||
testrigStartCmd := &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "start the gotosocial testrig server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return run(cmd.Context(), testrig.Start)
|
||||
},
|
||||
}
|
||||
testrigStartCmd := &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "start the gotosocial testrig server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return run(cmd.Context(), testrig.Start)
|
||||
},
|
||||
}
|
||||
|
||||
testrigCmd.AddCommand(testrigStartCmd)
|
||||
return testrigCmd
|
||||
testrigCmd.AddCommand(testrigStartCmd)
|
||||
return testrigCmd
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue