diff options
| -rw-r--r-- | app/app_test.go | 2 | ||||
| -rw-r--r-- | app/controllers/dashboard/controller_test.go | 2 | ||||
| -rw-r--r-- | app/controllers/sessions/controller_test.go | 4 | ||||
| -rw-r--r-- | app/controllers/sessions/service_test.go | 4 | ||||
| -rw-r--r-- | app/controllers/sparkles/controller_test.go | 2 | ||||
| -rw-r--r-- | app/middleware/id_token_test.go | 4 | ||||
| -rw-r--r-- | app/middleware/require_user_test.go | 2 | ||||
| -rw-r--r-- | app/middleware/user_test.go | 2 | ||||
| -rw-r--r-- | pkg/oidc/oidc_test.go | 3 | ||||
| -rw-r--r-- | pkg/oidc/test_server.go (renamed from pkg/test/oidc_server.go) | 4 | ||||
| -rw-r--r-- | pkg/test/http.go | 68 |
11 files changed, 14 insertions, 83 deletions
diff --git a/app/app_test.go b/app/app_test.go index bf706bc..8817a3c 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/xlgmokha/x/pkg/test" "github.com/xlgmokha/x/pkg/x" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestApp(t *testing.T) { diff --git a/app/controllers/dashboard/controller_test.go b/app/controllers/dashboard/controller_test.go index 30a9acc..c717a74 100644 --- a/app/controllers/dashboard/controller_test.go +++ b/app/controllers/dashboard/controller_test.go @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestController(t *testing.T) { diff --git a/app/controllers/sessions/controller_test.go b/app/controllers/sessions/controller_test.go index c86f2f8..a29041e 100644 --- a/app/controllers/sessions/controller_test.go +++ b/app/controllers/sessions/controller_test.go @@ -11,17 +11,17 @@ import ( "github.com/oauth2-proxy/mockoidc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/test" "github.com/xlgmokha/x/pkg/x" xcfg "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" ) func TestSessions(t *testing.T) { - srv := test.NewOIDCServer(t) + srv := oidc.NewTestServer(t) defer srv.Close() clientID := srv.MockOIDC.Config().ClientID diff --git a/app/controllers/sessions/service_test.go b/app/controllers/sessions/service_test.go index e5e08fa..81248ca 100644 --- a/app/controllers/sessions/service_test.go +++ b/app/controllers/sessions/service_test.go @@ -7,14 +7,14 @@ import ( "github.com/oauth2-proxy/mockoidc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" ) func TestService(t *testing.T) { - srv := test.NewOIDCServer(t) + srv := oidc.NewTestServer(t) defer srv.Close() clientID := srv.MockOIDC.Config().ClientID diff --git a/app/controllers/sparkles/controller_test.go b/app/controllers/sparkles/controller_test.go index c158f32..b2c7752 100644 --- a/app/controllers/sparkles/controller_test.go +++ b/app/controllers/sparkles/controller_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/xlgmokha/x/pkg/serde" + "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/db" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestSparkles(t *testing.T) { diff --git a/app/middleware/id_token_test.go b/app/middleware/id_token_test.go index 06e9c96..95d9b40 100644 --- a/app/middleware/id_token_test.go +++ b/app/middleware/id_token_test.go @@ -10,16 +10,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/xlgmokha/x/pkg/log" + "github.com/xlgmokha/x/pkg/test" "github.com/xlgmokha/x/pkg/x" xcfg "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web" "golang.org/x/oauth2" ) func TestIDToken(t *testing.T) { - srv := test.NewOIDCServer(t) + srv := oidc.NewTestServer(t) defer srv.Close() client := &http.Client{Transport: &web.Transport{Logger: log.New(os.Stdout, log.Fields{})}} diff --git a/app/middleware/require_user_test.go b/app/middleware/require_user_test.go index 92734b2..07cbf92 100644 --- a/app/middleware/require_user_test.go +++ b/app/middleware/require_user_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestRequireUser(t *testing.T) { diff --git a/app/middleware/user_test.go b/app/middleware/user_test.go index 3e2425c..e1bbcf9 100644 --- a/app/middleware/user_test.go +++ b/app/middleware/user_test.go @@ -6,12 +6,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/test" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/cfg" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/db" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/pls" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestUser(t *testing.T) { diff --git a/pkg/oidc/oidc_test.go b/pkg/oidc/oidc_test.go index 3318f18..47a58ba 100644 --- a/pkg/oidc/oidc_test.go +++ b/pkg/oidc/oidc_test.go @@ -6,11 +6,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test" ) func TestOpenID(t *testing.T) { - srv := test.NewOIDCServer(t) + srv := NewTestServer(t) defer srv.Close() t.Run("GET /.well-known/openid-configuration", func(t *testing.T) { diff --git a/pkg/test/oidc_server.go b/pkg/oidc/test_server.go index c635df0..5a25549 100644 --- a/pkg/test/oidc_server.go +++ b/pkg/oidc/test_server.go @@ -1,4 +1,4 @@ -package test +package oidc import ( "net/http" @@ -19,7 +19,7 @@ type TestServer struct { *testing.T } -func NewOIDCServer(t *testing.T) *TestServer { +func NewTestServer(t *testing.T) *TestServer { srv, err := mockoidc.Run() require.NoError(t, err) diff --git a/pkg/test/http.go b/pkg/test/http.go deleted file mode 100644 index b65ccc9..0000000 --- a/pkg/test/http.go +++ /dev/null @@ -1,68 +0,0 @@ -package test - -import ( - "bytes" - "context" - "io" - "net/http" - "net/http/httptest" - - xcontext "github.com/xlgmokha/x/pkg/context" - "github.com/xlgmokha/x/pkg/serde" - "github.com/xlgmokha/x/pkg/x" -) - -type RequestOption x.Option[*http.Request] - -func Request(method, target string, options ...RequestOption) *http.Request { - request := httptest.NewRequest(method, target, nil) - for _, option := range options { - request = option(request) - } - return request -} - -func RequestResponse(method, target string, options ...RequestOption) (*http.Request, *httptest.ResponseRecorder) { - return Request(method, target, options...), httptest.NewRecorder() -} - -func WithAcceptHeader(value serde.MediaType) RequestOption { - return WithRequestHeader("Accept", string(value)) -} - -func WithRequestHeader(key, value string) RequestOption { - return func(r *http.Request) *http.Request { - r.Header.Set(key, value) - return r - } -} - -func WithContentType[T any](item T, mediaType serde.MediaType) RequestOption { - body := bytes.NewBuffer(nil) - x.Check(serde.To[T](body, item, mediaType)) - return WithRequestBody(io.NopCloser(body)) -} - -func WithRequestBody(body io.ReadCloser) RequestOption { - return func(r *http.Request) *http.Request { - r.Body = body - return r - } -} - -func WithContext(ctx context.Context) RequestOption { - return func(r *http.Request) *http.Request { - return r.WithContext(ctx) - } -} - -func WithContextKeyValue[T any](ctx context.Context, key xcontext.Key[T], item T) RequestOption { - return WithContext(key.With(ctx, item)) -} - -func WithCookie(cookie *http.Cookie) RequestOption { - return func(r *http.Request) *http.Request { - r.AddCookie(cookie) - return r - } -} |
