522fa83568
* sdk/logical: handle empty token type string values as TokenTypeDefault * add test case for missing token_type value
44 lines
756 B
Go
44 lines
756 B
Go
package logical
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestJSONSerialization(t *testing.T) {
|
|
tt := TokenTypeDefaultBatch
|
|
s, err := json.Marshal(tt)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var utt TokenType
|
|
err = json.Unmarshal(s, &utt)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if tt != utt {
|
|
t.Fatalf("expected %v, got %v", tt, utt)
|
|
}
|
|
|
|
utt = TokenTypeDefault
|
|
err = json.Unmarshal([]byte(`"default-batch"`), &utt)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if tt != utt {
|
|
t.Fatalf("expected %v, got %v", tt, utt)
|
|
}
|
|
|
|
// Test on an empty value, which should unmarshal into TokenTypeDefault
|
|
tt = TokenTypeDefault
|
|
err = json.Unmarshal([]byte(`""`), &utt)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if tt != utt {
|
|
t.Fatalf("expected %v, got %v", tt, utt)
|
|
}
|
|
}
|