1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-25 18:15:57 +01:00
galene/token/token_test.go
Juliusz Chroboczek 3c0dbf5e9b Reliably return an error from token.Parse.
We would sometimes return nil cast to an interface with no error,
which would cause the server to crash with a null dereference.
2023-05-14 21:14:59 +02:00

31 lines
547 B
Go

package token
import (
"testing"
"path/filepath"
"os"
)
func TestBad(t *testing.T) {
d := t.TempDir()
tokens = state{
filename: filepath.Join(d, "test.jsonl"),
}
f, err := os.OpenFile(tokens.filename,
os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0600,
)
if err != nil {
t.Fatalf("Create: %v", err)
}
defer f.Close()
token, err := Parse("foo", nil)
if err == nil {
t.Errorf("Expected error, got %v", token)
}
token, err = Parse("foo", []map[string]interface{}{})
if err == nil {
t.Errorf("Expected error, got %v", token)
}
}