Skip to content

Commit

Permalink
#146: Covered the telemetry by tests (#176)
Browse files Browse the repository at this point in the history
Improve general coverage of the codebase:
- covered a few configs by tests
- file content expansion in configurations
  • Loading branch information
roma-glushko authored Mar 17, 2024
1 parent a04eccf commit 3742035
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pkg/api/http/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package http

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestHTTPConfig_DefaultConfig(t *testing.T) {
config := DefaultServerConfig()

require.NotNil(t, config.Address())
require.NotNil(t, config.ToServer())
}
21 changes: 21 additions & 0 deletions pkg/config/expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,24 @@ func TestExpander_EnvVarExpanded(t *testing.T) {
assert.Equal(t, topP, cfg.Params[0].Value)
assert.Equal(t, fmt.Sprintf("$%v", budget), cfg.Params[1].Value)
}

func TestExpander_FileContentExpanded(t *testing.T) {
content, err := os.ReadFile(filepath.Clean(filepath.Join(".", "testdata", "expander.file.yaml")))
require.NoError(t, err)

expander := Expander{}
updatedContent := string(expander.Expand(content))

require.NotContains(t, updatedContent, "${file:")
require.Contains(t, updatedContent, "sk-fakeapi-token")
}

func TestExpander_FileDoesntExist(t *testing.T) {
content, err := os.ReadFile(filepath.Clean(filepath.Join(".", "testdata", "expander.file.notfound.yaml")))
require.NoError(t, err)

expander := Expander{}
updatedContent := string(expander.Expand(content))

require.NotContains(t, updatedContent, "${file:")
}
6 changes: 6 additions & 0 deletions pkg/config/testdata/expander.file.notfound.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: "OpenAI"
api_key: "${file:./testdata/doesntexist}"

params:
- name: budget
value: "$$${file:./testdata/doesntexist}"
6 changes: 6 additions & 0 deletions pkg/config/testdata/expander.file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: "OpenAI"
api_key: "${file:./testdata/openai_key}"

params:
- name: budget
value: "$$${file:./testdata/openai_key}"
1 change: 1 addition & 0 deletions pkg/config/testdata/openai_key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sk-fakeapi-token
13 changes: 13 additions & 0 deletions pkg/routers/retry/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package retry

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestRetryConfig_DefaultConfig(t *testing.T) {
config := DefaultExpRetryConfig()

require.NotNil(t, config)
}
5 changes: 4 additions & 1 deletion pkg/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ func (r *LangRouter) ChatStream(

// no providers were available to handle the request,
// so we have to wait a bit with a hope there is some available next time
r.tel.L().Warn("No healthy model found to serve streaming chat request, wait and retry", zap.String("routerID", r.ID()))
r.tel.L().Warn(
"No healthy model found to serve streaming chat request, wait and retry",
zap.String("routerID", r.ID()),
)

err := retryIterator.WaitNext(ctx)
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions pkg/telemetry/logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package telemetry

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestLogging_PlainOutputSetup(t *testing.T) {
config := LogConfig{
Encoding: "console",
}
zapConfig := config.ToZapConfig()

require.Equal(t, "console", config.Encoding)
require.NotNil(t, zapConfig)
require.Equal(t, "console", zapConfig.Encoding)
}

func TestLogging_JSONOutputSetup(t *testing.T) {
config := DefaultLogConfig()
zapConfig := config.ToZapConfig()

require.Equal(t, "json", config.Encoding)
require.NotNil(t, zapConfig)
require.Equal(t, "json", zapConfig.Encoding)
}
12 changes: 12 additions & 0 deletions pkg/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package telemetry

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestTelemetry_Creation(t *testing.T) {
_, err := NewTelemetry(DefaultConfig())
require.NoError(t, err)
}

0 comments on commit 3742035

Please sign in to comment.