-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adds unit test coverage checks (#249)
**Commit Message**: This introduces the unit test coverage checks in GHA. Note that this doesn't utilize the integration tests (test-extproc,test-controller and test-e2e), so the coverage will be checked solely on the unit tests without relying on the external binaries etc. One left TODO is to remove the exclusion of controller package which requires a bit of refactoring, so i will follow up in a separate PR. --------- Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
- Loading branch information
Showing
15 changed files
with
474 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This is the configuration file for /~https://github.com/vladopajic/go-test-coverage | ||
|
||
profile: ./out/go-test-coverage.out | ||
local-prefix: "github.com/envoyproxy/ai-gateway/" | ||
|
||
threshold: | ||
file: 70 | ||
# TODO: increase to 90. | ||
package: 80 | ||
# TODO: increase to 95. | ||
total: 83 | ||
|
||
exclude: | ||
paths: | ||
- ^api/ | ||
- ^examples/ | ||
- apischema/ | ||
- cmd/ | ||
- tests/internal/envtest.go | ||
# TODO: Remove this exclusion. | ||
- internal/controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package extensionserver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/go-logr/logr" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
logger := logr.Discard() | ||
s := New(logger) | ||
require.NotNil(t, s) | ||
} | ||
|
||
func TestCheck(t *testing.T) { | ||
logger := logr.Discard() | ||
s := New(logger) | ||
_, err := s.Check(context.Background(), nil) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestWatch(t *testing.T) { | ||
logger := logr.Discard() | ||
s := New(logger) | ||
err := s.Watch(nil, nil) | ||
require.Error(t, err) | ||
require.Equal(t, "rpc error: code = Unimplemented desc = Watch is not implemented", err.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package backendauth | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/envoyproxy/ai-gateway/filterapi" | ||
) | ||
|
||
func TestNewHandler(t *testing.T) { | ||
awsFile := t.TempDir() + "/awstest" | ||
err := os.WriteFile(awsFile, []byte(` | ||
[default] | ||
aws_access_key_id = test | ||
aws_secret_access_key = test | ||
`), 0o600) | ||
require.NoError(t, err) | ||
|
||
apiKeyFile := t.TempDir() + "/apikey" | ||
err = os.WriteFile(apiKeyFile, []byte("TEST"), 0o600) | ||
require.NoError(t, err) | ||
|
||
for _, tt := range []struct { | ||
name string | ||
config *filterapi.BackendAuth | ||
}{ | ||
{ | ||
name: "AWSAuth", | ||
config: &filterapi.BackendAuth{AWSAuth: &filterapi.AWSAuth{ | ||
Region: "us-west-2", CredentialFileName: awsFile, | ||
}}, | ||
}, | ||
{ | ||
name: "APIKey", | ||
config: &filterapi.BackendAuth{ | ||
APIKey: &filterapi.APIKeyAuth{Filename: apiKeyFile}, | ||
}, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := NewHandler(tt.config) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.