Exemplo n.º 1
0
func TestUserRequest(t *testing.T) {
	//request 1 : unscoped password authentication
	request1Raw := `{"user":{"name":"James Doe","domain_id":"1789d1","default_project_id":"263fd9","email":"*****@*****.**","description":"James Doe user","password":"******","enabled":true}}`
	request1Struct := &UserRequest{
		User: &User{
			DefaultProjectId: "263fd9",
			Description:      "James Doe user",
			DomainId:         "1789d1",
			Email:            "*****@*****.**",
			Enabled:          true,
			Name:             "James Doe",
			Password:         "******",
		},
	}

	request1Unmarshal := &UserRequest{}
	err := json.Unmarshal([]byte(request1Raw), request1Unmarshal)

	testutil.IsNil(t, err)
	testutil.Equals(t, request1Struct, request1Unmarshal)

	request1Marshal, err := json.Marshal(request1Struct)
	testutil.IsNil(t, err)
	testutil.Equals(t, request1Raw, string(request1Marshal))
}
Exemplo n.º 2
0
func TestTokenCache(t *testing.T) {
	c := NewTokenCache(nil, 300)
	t1 := &types.Token{
		Methods:   []string{"password"},
		ExpiresAt: &util.Iso8601DateTime{time.Date(2015, time.November, 06, 15, 32, 17, 893769000, time.UTC)},
		Extras:    make(map[string]interface{}),
		User: &types.User{
			Id:   "423f19a4ac1e4f48bbb4180756e6eb6c",
			Name: "admin",
			Domain: &types.Domain{
				Id:   "default",
				Name: "Default",
			},
		},
	}

	err := c.Set("123", t1)
	if err != nil {
		t.Error(err)
	}

	t2, err := c.Get("123")
	if err != nil {
		t.Error(err)
	}

	testutil.Equals(t, t1, t2)

}
Exemplo n.º 3
0
func TestVersion(t *testing.T) {
	version := &Version{}
	err := json.Unmarshal([]byte(v), version)
	if err != nil {
		t.Error("Failed to unmarshal version: %s", err)
	}

	testutil.Equals(t, version, structV)
}
Exemplo n.º 4
0
func TestUnmarshalValidTimeTest(t *testing.T) {
	val := timeTest{}
	err := json.Unmarshal([]byte(testValue), &val)
	testutil.IsNil(t, err)
	testutil.Equals(t, timeTestValue.CreatedAt.Time, val.CreatedAt.Time)
}
Exemplo n.º 5
0
func TestMarshalTimeTest(t *testing.T) {
	bytes, _ := json.Marshal(timeTestValue)

	testutil.Equals(t, testValue, string(bytes))
}
Exemplo n.º 6
0
func TestUserResponse(t *testing.T) {
	response1Raw := `{
    "user": {
        "default_project_id": "263fd9",
        "description": "James Doe user",
        "domain_id": "1789d1",
        "email": "*****@*****.**",
        "enabled": true,
        "id": "ff4e51",
        "links": {
            "self": "https://*****:*****@example.com",
			Enabled:          true,
			Name:             "James Doe",
			Id:               "ff4e51",
			Links: Link{
				"self": "https://*****:*****@example.com",
				"enabled": true,
				"id": "4ab84ab39de54f4d96eaff8f2145a7cd",
				"links": {
					"self": "http://*****:*****@example.com",
				Enabled:  true,
				Name:     "swiftusertest1",
				Id:       "4ab84ab39de54f4d96eaff8f2145a7cd",
				Links: Link{
					"self": "http://localhost:5000/v3/users/4ab84ab39de54f4d96eaff8f2145a7cd",
				},
			},
		},
	}

	response2Unmarshal := &UsersResponse{}
	err = json.Unmarshal([]byte(response2Raw), response2Unmarshal)
	testutil.IsNil(t, err)
	testutil.Equals(t, response2Struct, response2Unmarshal)

}