Skip to content

Commit 310bda7

Browse files
committed
config: reorganize
1 parent 286a673 commit 310bda7

File tree

9 files changed

+28
-24
lines changed

9 files changed

+28
-24
lines changed

cmd/catalyst/catalyst.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"syscall"
88

99
"github.com/golang/glog"
10+
"github.com/livepeer/catalyst/cmd/catalyst/config"
1011
"github.com/livepeer/catalyst/cmd/downloader/constants"
11-
"github.com/livepeer/catalyst/config"
1212
"github.com/peterbourgon/ff/v3"
1313
)
1414

@@ -36,7 +36,7 @@ func main() {
3636
ff.WithEnvVarSplit(","),
3737
)
3838
flag.CommandLine.Parse(nil)
39-
conf, sql, err := config.Config(&cli)
39+
conf, sql, err := config.GenerateConfig(&cli)
4040
if err != nil {
4141
panic(err)
4242
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
"github.com/doug-martin/goqu/v9"
11-
"github.com/livepeer/catalyst/test/e2e"
1211
)
1312

1413
//go:embed full-stack.json
@@ -45,15 +44,15 @@ func (d DBObject) Table() string {
4544
panic("table not found")
4645
}
4746

48-
func Config(cli *Cli) ([]byte, []byte, error) {
47+
func GenerateConfig(cli *Cli) ([]byte, []byte, error) {
4948
if cli.Secret == "" {
5049
return []byte{}, []byte{}, fmt.Errorf("CATALYST_SECRET parameter is required")
5150
}
5251
u, err := url.Parse(cli.PublicURL)
5352
if err != nil {
5453
return []byte{}, []byte{}, err
5554
}
56-
var conf e2e.MistConfig
55+
var conf MistConfig
5756
err = json.Unmarshal(fullstack, &conf)
5857
if err != nil {
5958
return []byte{}, []byte{}, err
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9-
"github.com/livepeer/catalyst/test/e2e"
109
"github.com/stretchr/testify/require"
1110
)
1211

1312
//go:embed full-stack.spec.json
1413
var spec []byte
1514

1615
func TestSpecIsValid(t *testing.T) {
17-
err := json.Unmarshal(fullstack, &e2e.MistConfig{})
16+
err := json.Unmarshal(fullstack, &MistConfig{})
1817
require.NoError(t, err)
19-
err = json.Unmarshal(spec, &e2e.MistConfig{})
18+
err = json.Unmarshal(spec, &MistConfig{})
2019
require.NoError(t, err)
2120
}
2221

2322
func TestItCanPassthroughEmptyConfig(t *testing.T) {
24-
generated, _, err := Config(&Cli{
23+
generated, _, err := GenerateConfig(&Cli{
2524
Secret: "44444444-4444-4444-4444-444444444444",
2625
PublicURL: "https://example.com",
2726
})
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package e2e
1+
package config
22

33
import (
44
"encoding/json"
@@ -174,7 +174,7 @@ type MistConfig struct {
174174
ExtWriters []any `json:"extwriters"`
175175
}
176176

177-
func defaultMistConfig(host, sourceOutput string) MistConfig {
177+
func DefaultMistConfig(host, sourceOutput string) MistConfig {
178178
return MistConfig{
179179
Account: map[string]Account{
180180
"test": {
@@ -276,8 +276,8 @@ func defaultMistConfig(host, sourceOutput string) MistConfig {
276276
}
277277
}
278278

279-
func defaultMistConfigWithLivepeerProcess(host, sourceOutput string) MistConfig {
280-
mc := defaultMistConfig(host, sourceOutput)
279+
func DefaultMistConfigWithLivepeerProcess(host, sourceOutput string) MistConfig {
280+
mc := DefaultMistConfig(host, sourceOutput)
281281
s := mc.Streams["stream"]
282282
s.Processes = []*Process{
283283
{
@@ -319,7 +319,7 @@ func (m *MistConfig) toFile(file *os.File) error {
319319
return nil
320320
}
321321

322-
func (m *MistConfig) toTmpFile(dir string) (string, error) {
322+
func (m *MistConfig) ToTmpFile(dir string) (string, error) {
323323
tmpFile, err := ioutil.TempFile(dir, "mist-config-*.json")
324324
if err != nil {
325325
return "", err

test/e2e/e2e_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ import (
1717
"time"
1818

1919
"github.com/golang/glog"
20+
"github.com/livepeer/catalyst/cmd/catalyst/config"
2021
"github.com/stretchr/testify/assert"
2122
"github.com/stretchr/testify/require"
2223
"github.com/testcontainers/testcontainers-go"
2324
)
2425

2526
const (
26-
webConsolePort = "4242"
27-
httpPort = "8080"
28-
rtmpPort = "1935"
27+
webConsolePort = "4242"
28+
httpPort = "8080"
29+
rtmpPort = "1935"
30+
advertisePort = "9935"
31+
catalystAPIPort = "7979"
32+
catalystAPIInternalPort = "7878"
33+
boxPort = "8888"
2934
)
3035

3136
type cliParams struct {
@@ -94,7 +99,7 @@ func TestMultiNodeCatalyst(t *testing.T) {
9499
h2 := randomString("catalyst-")
95100

96101
// when
97-
c1 := startCatalyst(ctx, t, h1, network.name, defaultMistConfig(h1, ""))
102+
c1 := startCatalyst(ctx, t, h1, network.name, config.DefaultMistConfig(h1, ""))
98103
defer c1.Terminate(ctx)
99104
c2 := startCatalyst(ctx, t, h2, network.name, mistConfigConnectTo(h2, h1))
100105
defer c2.Terminate(ctx)
@@ -119,8 +124,8 @@ func createNetwork(ctx context.Context, t *testing.T) *network {
119124
return &network{Network: net, name: name}
120125
}
121126

122-
func mistConfigConnectTo(host string, connectToHost string) MistConfig {
123-
mc := defaultMistConfig(host, "")
127+
func mistConfigConnectTo(host string, connectToHost string) config.MistConfig {
128+
mc := config.DefaultMistConfig(host, "")
124129
for i, p := range mc.Config.Protocols {
125130
if p.Connector == "livepeer-catalyst-api" {
126131
p.RetryJoin = fmt.Sprintf("%s:%s", connectToHost, advertisePort)
@@ -138,12 +143,12 @@ func (lc *logConsumer) Accept(l testcontainers.Log) {
138143
glog.Infof("[%s] %s", lc.name, string(l.Content))
139144
}
140145

141-
func startCatalyst(ctx context.Context, t *testing.T, hostname, network string, mc MistConfig) *catalystContainer {
146+
func startCatalyst(ctx context.Context, t *testing.T, hostname, network string, mc config.MistConfig) *catalystContainer {
142147
return startCatalystWithEnv(ctx, t, hostname, network, mc, nil)
143148
}
144149

145-
func startCatalystWithEnv(ctx context.Context, t *testing.T, hostname, network string, mc MistConfig, env map[string]string) *catalystContainer {
146-
mcPath, err := mc.toTmpFile(t.TempDir())
150+
func startCatalystWithEnv(ctx context.Context, t *testing.T, hostname, network string, mc config.MistConfig, env map[string]string) *catalystContainer {
151+
mcPath, err := mc.ToTmpFile(t.TempDir())
147152
require.NoError(t, err)
148153
configAbsPath := filepath.Dir(mcPath)
149154
mcFile := filepath.Base(mcPath)

test/e2e/vod_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
"github.com/livepeer/catalyst/cmd/catalyst/config"
1112
"github.com/minio/minio-go/v7"
1213
"github.com/minio/minio-go/v7/pkg/credentials"
1314
"github.com/stretchr/testify/require"
@@ -43,7 +44,7 @@ func TestVod(t *testing.T) {
4344
createDestBucket(t, m)
4445

4546
h := randomString("catalyst-")
46-
c := startCatalyst(ctx, t, h, network.name, defaultMistConfigWithLivepeerProcess(h, sourceOutput(m)))
47+
c := startCatalyst(ctx, t, h, network.name, config.DefaultMistConfigWithLivepeerProcess(h, sourceOutput(m)))
4748
defer c.Terminate(ctx)
4849
waitForCatalystAPI(t, c)
4950

0 commit comments

Comments
 (0)