func TestByteSizeDoTheRightThing(t *testing.T) {
	value, err := bytesize.Parse([]byte("1 kb"))
	if err != nil {
		t.Errorf("Failed to parse byte size. Error: %v", err)
	}
	if float64(value) != 1024 {
		t.Errorf("Failed to parse byte size correctly. Value: %v", float64(value))
	}

	value, err = bytesize.Parse([]byte("1 mB"))
	if err != nil {
		t.Errorf("Failed to parse byte size. Error: %v", err)
	}
	if float64(value) != 1024*1024 {
		t.Errorf("Failed to parse byte size correctly. Value: %v", float64(value))
	}

	value, err = bytesize.Parse([]byte("1 GB"))
	if err != nil {
		t.Errorf("Failed to parse byte size. Error: %v", err)
	}
	if float64(value) != 1024*1024*1024 {
		t.Errorf("Failed to parse byte size correctly. Value: %v", float64(value))
	}
}
Beispiel #2
0
func load() (*Options, error) {
	var drippers, startID int
	var heapStr string

	flag.StringVar(&licenseKey, "key", "", "License key")
	flag.IntVar(&startID, "start", 1, "ID of first dripper")
	flag.IntVar(&drippers, "count", 1, "Number of drippers")
	flag.StringVar(&heapStr, "heap", "512 GB", "Heap size to report")
	flag.BoolVar(&debugMode, "debug", false, "Dump HTTP traffic")
	flag.Parse()

	if licenseKey == "" {
		return nil, errors.New("License key required")
	}

	heapSize, err := bytesize.Parse([]byte(heapStr))
	if err != nil {
		return nil, err
	}

	return &Options{
		Drippers: drippers,
		HeapSize: uint64(heapSize),
		StartID:  startID,
	}, nil
}
Beispiel #3
0
func (cd *CheckDocker) getByteSizeDriverStatus(key string) (bytesize.ByteSize, error) {
	var statusInArray [][]string

	err := json.Unmarshal([]byte(cd.dockerInfoData.Get("DriverStatus")), &statusInArray)

	if err != nil {
		return -1, errors.New("Unable to extract DriverStatus info.")
	}

	for _, status := range statusInArray {
		if status[0] == key {
			return bytesize.Parse([]byte(status[1]))
		}
	}

	return -1, errors.New(fmt.Sprintf("DriverStatus does not contain \"%v\"", key))
}