mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add functions/vendor files
This commit is contained in:
38
vendor/github.com/go-openapi/runtime/flagext/byte_size.go
generated
vendored
Normal file
38
vendor/github.com/go-openapi/runtime/flagext/byte_size.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package flagext
|
||||
|
||||
import (
|
||||
"github.com/docker/go-units"
|
||||
)
|
||||
|
||||
// ByteSize used to pass byte sizes to a go-flags CLI
|
||||
type ByteSize int
|
||||
|
||||
// MarshalFlag implements go-flags Marshaller interface
|
||||
func (b ByteSize) MarshalFlag() (string, error) {
|
||||
return units.HumanSize(float64(b)), nil
|
||||
}
|
||||
|
||||
// UnmarshalFlag implements go-flags Unmarshaller interface
|
||||
func (b *ByteSize) UnmarshalFlag(value string) error {
|
||||
sz, err := units.FromHumanSize(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*b = ByteSize(int(sz))
|
||||
return nil
|
||||
}
|
||||
|
||||
// String method for a bytesize (pflag value and stringer interface)
|
||||
func (b ByteSize) String() string {
|
||||
return units.HumanSize(float64(b))
|
||||
}
|
||||
|
||||
// Set the value of this bytesize (pflag value interfaces)
|
||||
func (b *ByteSize) Set(value string) error {
|
||||
return b.UnmarshalFlag(value)
|
||||
}
|
||||
|
||||
// Type returns the type of the pflag value (pflag value interface)
|
||||
func (b *ByteSize) Type() string {
|
||||
return "byte-size"
|
||||
}
|
||||
43
vendor/github.com/go-openapi/runtime/flagext/byte_size_test.go
generated
vendored
Normal file
43
vendor/github.com/go-openapi/runtime/flagext/byte_size_test.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package flagext
|
||||
|
||||
import "testing"
|
||||
import "github.com/stretchr/testify/assert"
|
||||
|
||||
func TestMarshalBytesize(t *testing.T) {
|
||||
v, err := ByteSize(1024).MarshalFlag()
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, "1.024kB", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringBytesize(t *testing.T) {
|
||||
v := ByteSize(2048).String()
|
||||
assert.Equal(t, "2.048kB", v)
|
||||
}
|
||||
|
||||
func TestUnmarshalBytesize(t *testing.T) {
|
||||
var b ByteSize
|
||||
err := b.UnmarshalFlag("notASize")
|
||||
assert.Error(t, err)
|
||||
|
||||
err = b.UnmarshalFlag("1MB")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, ByteSize(1000000), b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetBytesize(t *testing.T) {
|
||||
var b ByteSize
|
||||
err := b.Set("notASize")
|
||||
assert.Error(t, err)
|
||||
|
||||
err = b.Set("2MB")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, ByteSize(2000000), b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypeBytesize(t *testing.T) {
|
||||
var b ByteSize
|
||||
assert.Equal(t, "byte-size", b.Type())
|
||||
}
|
||||
Reference in New Issue
Block a user