func TestGetServiceList(t *testing.T) {
	cases := []struct {
		serviceList     *api.ServiceList
		expectedActions []string
		expected        *ServiceList
	}{
		{
			serviceList:     &api.ServiceList{},
			expectedActions: []string{"list"},
			expected:        &ServiceList{Services: make([]Service, 0)},
		}, {
			serviceList: &api.ServiceList{
				Items: []api.Service{
					{ObjectMeta: api.ObjectMeta{
						Name: "test-service", Namespace: "test-namespace",
					}},
				}},
			expectedActions: []string{"list"},
			expected: &ServiceList{
				ListMeta: common.ListMeta{TotalItems: 1},
				Services: []Service{
					{
						ObjectMeta: common.ObjectMeta{
							Name:      "test-service",
							Namespace: "test-namespace",
						},
						TypeMeta:         common.TypeMeta{Kind: common.ResourceKindService},
						InternalEndpoint: common.Endpoint{Host: "test-service.test-namespace"},
					},
				},
			},
		},
	}

	for _, c := range cases {
		fakeClient := testclient.NewSimpleFake(c.serviceList)

		actual, _ := GetServiceList(fakeClient, common.NewNamespaceQuery(nil), dataselect.NoDataSelect)

		actions := fakeClient.Actions()
		if len(actions) != len(c.expectedActions) {
			t.Errorf("Unexpected actions: %v, expected %d actions got %d", actions,
				len(c.expectedActions), len(actions))
			continue
		}

		for i, verb := range c.expectedActions {
			if actions[i].GetVerb() != verb {
				t.Errorf("Unexpected action: %+v, expected %s",
					actions[i], verb)
			}
		}

		if !reflect.DeepEqual(actual, c.expected) {
			t.Errorf("GetServiceList(client) == got\n%#v, expected\n %#v", actual, c.expected)
		}
	}
}
Example #2
0
func TestNewSecretListCreation(t *testing.T) {
	cases := []struct {
		k8sRs     *api.SecretList
		expected  *SecretList
		namespace *common.NamespaceQuery
	}{
		{
			k8SecretList,
			&SecretList{
				Secrets: []Secret{
					{
						ObjectMeta: common.ObjectMeta{
							Name:              "user1",
							Namespace:         "foo",
							CreationTimestamp: unversioned.Unix(111, 222),
						},
						TypeMeta: common.NewTypeMeta(common.ResourceKindSecret),
					},
					{
						ObjectMeta: common.ObjectMeta{
							Name:              "user2",
							Namespace:         "foo",
							CreationTimestamp: unversioned.Unix(111, 222),
						},
						TypeMeta: common.NewTypeMeta(common.ResourceKindSecret),
					},
				},
				ListMeta: common.ListMeta{2},
			},
			common.NewNamespaceQuery([]string{"foo"}),
		},
	}

	for _, c := range cases {
		actual := NewSecretList(c.k8sRs.Items, dataselect.NoDataSelect)
		if !reflect.DeepEqual(actual, c.expected) {
			t.Errorf("NewSecretList() ==\n          %#v\nExpected: %#v", actual, c.expected)
		}
	}
}