model/config/credential/Credential_test.go

70 lines
1.3 KiB
Go
Raw Permalink Normal View History

2018-08-30 11:12:07 +00:00
package credential
import (
"encoding/json"
"testing"
)
func TestCredentialsMap_UnmarshalJSON(t *testing.T) {
credentialsMap := CredentialsMap{
"SNMP": []*SNMPCredential{
&SNMPCredential{
Version: "2c",
Community: "public",
},
&SNMPCredential{
Version: "2c",
Community: "atgame",
},
},
"WINDOWS": []*WindowsCredential{
&WindowsCredential{
DomainName: "atgame.net",
User: "crusader",
Password: "1234",
},
},
}
b, err := json.Marshal(credentialsMap)
if nil != err {
t.Errorf("CredentialsMap.UnmarshalJSON() error = %v", err)
}
_credentialsMap := CredentialsMap{}
type args struct {
data []byte
}
tests := []struct {
name string
m CredentialsMap
args args
wantErr bool
}{
{
name: "1",
m: _credentialsMap,
args: args{
data: b,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.m.UnmarshalJSON(tt.args.data); (err != nil) != tt.wantErr {
t.Errorf("CredentialsMap.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
}
cs := tt.m["SNMP"].([]*SNMPCredential)
for _, c := range cs {
t.Log(c)
}
cs1 := tt.m["WINDOWS"].([]*WindowsCredential)
for _, c1 := range cs1 {
t.Log(c1)
}
})
}
}