-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from xmidt-org/feature/allow-source-in-valida…
…tors Feature/allow source in validators
- Loading branch information
Showing
9 changed files
with
623 additions
and
129 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
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,36 @@ | ||
// SPDX-FileCopyrightText: 2020 Comcast Cable Communications Management, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package bascule | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type testToken string | ||
|
||
func (tt testToken) Principal() string { return string(tt) } | ||
|
||
type mockValidator[S any] struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *mockValidator[S]) Validate(ctx context.Context, source S, token Token) (Token, error) { | ||
args := m.Called(ctx, source, token) | ||
t, _ := args.Get(0).(Token) | ||
return t, args.Error(1) | ||
} | ||
|
||
func (m *mockValidator[S]) ExpectValidate(ctx context.Context, source S, token Token) *mock.Call { | ||
return m.On("Validate", ctx, source, token) | ||
} | ||
|
||
func assertValidators[S any](t mock.TestingT, vs ...Validator[S]) (passed bool) { | ||
for _, v := range vs { | ||
passed = v.(*mockValidator[S]).AssertExpectations(t) && passed | ||
} | ||
|
||
return | ||
} |
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.