Exemple #1
0
func TestRegistryNewDup(t *testing.T) {
	lookupNode := node.LookupFunc(func(string) *api.Node {
		return nil
	})

	c, err := NewCache(1000)
	if err != nil {
		t.Error(err)
		return
	}

	r, err := NewRegistry(lookupNode, &mesosproto.ExecutorInfo{}, c)
	if err != nil {
		t.Error(err)
		return
	}

	new := r.New("", nil)
	dup := r.New("", nil)

	if !reflect.DeepEqual(new, dup) {
		t.Errorf(
			"expected new == dup, but got new %v dup %v",
			new, dup,
		)
	}
}
Exemple #2
0
func TestRegistryNew(t *testing.T) {
	for i, tt := range []struct {
		prototype *mesosproto.ExecutorInfo
		resources []*mesosproto.Resource
		want      *mesosproto.ExecutorInfo
	}{
		{
			prototype: &mesosproto.ExecutorInfo{
				ExecutorId: mesosutil.NewExecutorID("exec-id"),
			},
			resources: nil,
			want: &mesosproto.ExecutorInfo{
				ExecutorId: mesosutil.NewExecutorID("exec-id"),
			},
		}, {
			prototype: &mesosproto.ExecutorInfo{
				ExecutorId: mesosutil.NewExecutorID("exec-id"),
			},
			resources: []*mesosproto.Resource{},
			want: &mesosproto.ExecutorInfo{
				ExecutorId: mesosutil.NewExecutorID("exec-id"),
				Resources:  []*mesosproto.Resource{},
			},
		}, {
			prototype: &mesosproto.ExecutorInfo{
				ExecutorId: mesosutil.NewExecutorID("exec-id"),
				Name:       proto.String("foo"),
			},

			resources: []*mesosproto.Resource{
				scalar("foo", 1.0, "role1"),
				scalar("bar", 2.0, "role2"),
			},

			want: &mesosproto.ExecutorInfo{
				ExecutorId: mesosutil.NewExecutorID("exec-id"),
				Name:       proto.String("foo"),
				Resources: []*mesosproto.Resource{
					scalar("foo", 1.0, "role1"),
					scalar("bar", 2.0, "role2"),
				},
			},
		},
	} {
		lookupNode := node.LookupFunc(func(string) *api.Node {
			return nil
		})

		c, err := NewCache(1000)
		if err != nil {
			t.Error(err)
			continue
		}

		r, err := NewRegistry(lookupNode, tt.prototype, c)
		if err != nil {
			t.Error(err)
			continue
		}

		got := r.New("", tt.resources)

		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("test #%d\ngot  %v\nwant %v", i, got, tt.want)
		}
	}
}
Exemple #3
0
func TestRegistryGet(t *testing.T) {
	var lookupFunc func() *api.Node
	lookupNode := node.LookupFunc(func(hostname string) *api.Node {
		return lookupFunc()
	})

	prototype := &mesosproto.ExecutorInfo{
		Resources: []*mesosproto.Resource{
			scalar("foo", 1.0, "role1"),
		},
	}

	c, err := NewCache(1000)
	if err != nil {
		t.Error(err)
		return
	}

	r, err := NewRegistry(lookupNode, prototype, c)
	if err != nil {
		t.Error(err)
		return
	}

	var resources bytes.Buffer
	EncodeResources(&resources, prototype.GetResources())

	for i, tt := range []struct {
		apiNode *api.Node
		wantErr bool
	}{
		{
			apiNode: nil,
			wantErr: true,
		}, {
			apiNode: &api.Node{},
			wantErr: true,
		}, {
			apiNode: &api.Node{
				ObjectMeta: api.ObjectMeta{
					Annotations: map[string]string{},
				},
			},
			wantErr: true,
		}, {
			apiNode: &api.Node{
				ObjectMeta: api.ObjectMeta{
					Annotations: map[string]string{
						meta.ExecutorResourcesKey: resources.String(),
					},
				},
			},
			wantErr: false,
		},
	} {
		lookupFunc = func() *api.Node { return tt.apiNode }
		_, err := r.Get("")

		if tt.wantErr && err == nil {
			t.Errorf("test %d: want error but got none", i)
		}

		if !tt.wantErr && err != nil {
			t.Errorf("test %d error: %v", i, err)
		}
	}
}