mirror of
https://github.com/diamondburned/cchat.git
synced 2025-07-12 15:06:56 +00:00
This commit broke both the cchat API and its repository generation API to accomodate for custom error types, as the new Authenticator API now uses AuthenticateError over error to add in multi-stage authentication instead of the old method with the for loop. This commit also removed the multistage example documented in Authenticator, as the API is now clearer. This commit also added the WrapAuthenticateError helper function that wraps a normal error into an AuthenticateError that does not have a NextStage return. Backends should use this for
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package repository
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-test/deep"
|
|
)
|
|
|
|
const _goComment = `
|
|
// The authenticator interface allows for a multistage initial authentication
|
|
// API that the backend could use. Multistage is done by calling
|
|
// AuthenticateForm then Authenticate again forever until no errors are
|
|
// returned.
|
|
//
|
|
// var s *cchat.Session
|
|
// var err error
|
|
//
|
|
// for {
|
|
// // Pseudo-function to render the form and return the results of those
|
|
// // forms when the user confirms it.
|
|
// outputs := renderAuthForm(svc.AuthenticateForm())
|
|
//
|
|
// s, err = svc.Authenticate(outputs)
|
|
// if err != nil {
|
|
// renderError(errors.Wrap(err, "Error while authenticating"))
|
|
// continue // retry
|
|
// }
|
|
//
|
|
// break // success
|
|
// }`
|
|
|
|
// Trim away the prefix new line.
|
|
var goComment = _goComment[1:]
|
|
|
|
func TestComment(t *testing.T) {
|
|
var authenticator = Main[RootPath].Interface("Authenticator")
|
|
|
|
t.Run("godoc", func(t *testing.T) {
|
|
godoc := authenticator.Comment.GoString(0)
|
|
|
|
if eq := deep.Equal(goComment, godoc); eq != nil {
|
|
t.Fatal("go comment inequality:", eq)
|
|
}
|
|
})
|
|
}
|