You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-login/login/login_test.go

40 lines
817 B
Go

// Copyright 2017 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package login
import (
"context"
"errors"
"testing"
)
func TestWithError(t *testing.T) {
err := errors.New("Not Found")
ctx := context.Background()
ctx = WithError(ctx, err)
if ErrorFrom(ctx) != err {
t.Errorf("Expect error stored in context")
}
ctx = context.Background()
if ErrorFrom(ctx) != nil {
t.Errorf("Expect nil error in context")
}
}
func TestWithToken(t *testing.T) {
token := new(Token)
ctx := context.Background()
ctx = WithToken(ctx, token)
if TokenFrom(ctx) != token {
t.Errorf("Expect token stored in context")
}
ctx = context.Background()
if TokenFrom(ctx) != nil {
t.Errorf("Expect nil error in context")
}
}