Exemplo n.º 1
0
func TestConvertResourcesFull(t *testing.T) {
	source := composetypes.Resources{
		Limits: &composetypes.Resource{
			NanoCPUs:    "0.003",
			MemoryBytes: composetypes.UnitBytes(300000000),
		},
		Reservations: &composetypes.Resource{
			NanoCPUs:    "0.002",
			MemoryBytes: composetypes.UnitBytes(200000000),
		},
	}
	resources, err := convertResources(source)
	assert.NilError(t, err)

	expected := &swarm.ResourceRequirements{
		Limits: &swarm.Resources{
			NanoCPUs:    3000000,
			MemoryBytes: 300000000,
		},
		Reservations: &swarm.Resources{
			NanoCPUs:    2000000,
			MemoryBytes: 200000000,
		},
	}
	assert.DeepEqual(t, resources, expected)
}
Exemplo n.º 2
0
func transformHook(
	source reflect.Type,
	target reflect.Type,
	data interface{},
) (interface{}, error) {
	switch target {
	case reflect.TypeOf(types.External{}):
		return transformExternal(source, target, data)
	case reflect.TypeOf(make(map[string]string, 0)):
		return transformMapStringString(source, target, data)
	case reflect.TypeOf(types.UlimitsConfig{}):
		return transformUlimits(source, target, data)
	case reflect.TypeOf(types.UnitBytes(0)):
		return loadSize(data)
	}
	switch target.Kind() {
	case reflect.Struct:
		return transformStruct(source, target, data)
	}
	return data, nil
}