func TestAllocate(t *testing.T) {
	_, storage, _, si, destroyFunc := newStorage(t)
	defer destroyFunc()
	if err := si.Create(context.TODO(), key(), validNewRangeAllocation(), nil, 0); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}

	tests := []struct {
		name   string
		port   int
		errMsg string
	}{
		{
			name:   "Allocate base port",
			port:   basePortRange,
			errMsg: "",
		},
		{
			name:   "Allocate maximum from the port range",
			port:   basePortRange + sizePortRange - 1,
			errMsg: "",
		},
		{
			name:   "Allocate invalid port: base port minus 1",
			port:   basePortRange - 1,
			errMsg: fmt.Sprintf("provided port is not in the valid range. The range of valid ports is %d-%d", basePortRange, basePortRange+sizePortRange-1),
		},
		{
			name:   "Allocate invalid port: maximum port from the port range plus 1",
			port:   basePortRange + sizePortRange,
			errMsg: fmt.Sprintf("provided port is not in the valid range. The range of valid ports is %d-%d", basePortRange, basePortRange+sizePortRange-1),
		},
		{
			name:   "Allocate invalid port",
			port:   -2,
			errMsg: fmt.Sprintf("provided port is not in the valid range. The range of valid ports is %d-%d", basePortRange, basePortRange+sizePortRange-1),
		},
	}
	for _, tt := range tests {
		tt := tt // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
		t.Run(tt.name, func(t *testing.T) {
			err := storage.Allocate(tt.port)
			if (err == nil) != (tt.errMsg == "") {
				t.Fatalf("Error expected %v, received %v", tt.errMsg, err)
			}
			if err != nil && err.Error() != tt.errMsg {
				t.Fatalf("Error message expected %v, received %v", tt.errMsg, err)
			}
		})
	}

}
// TestAllocate fails to allocate ports out of the valid port range
TestAllocate fails to allocate ports out of the valid port range
// TestAllocate fails to allocate ports out of the valid port range
func TestAllocate(t *testing.T) {
	_, storage, _, si, destroyFunc := newStorage(t)
	defer destroyFunc()
	if err := si.Create(context.TODO(), key(), validNewRangeAllocation(), nil, 0); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	tests := []struct {
		name   string
		port   int
		errMsg string
	}{
		{
			name:   "Allocate base port",
			port:   basePortRange,
			errMsg: "",
		},
		{
			name:   "Allocate maximum from the port range",
			port:   basePortRange + sizePortRange - 1,
			errMsg: "",
		},
		{
			name:   "Allocate invalid port: base port minus 1",
			port:   basePortRange - 1,
			errMsg: fmt.Sprintf("provided port is not in the valid range. The range of valid ports is %d-%d", basePortRange, basePortRange+sizePortRange-1),
		},
		{
			name:   "Allocate invalid port: maximum port from the port range plus 1",
			port:   basePortRange + sizePortRange,
			errMsg: fmt.Sprintf("provided port is not in the valid range. The range of valid ports is %d-%d", basePortRange, basePortRange+sizePortRange-1),
		},
		{
			name:   "Allocate invalid port",
			port:   -2,
			errMsg: fmt.Sprintf("provided port is not in the valid range. The range of valid ports is %d-%d", basePortRange, basePortRange+sizePortRange-1),
		},
	}
	for _, tt := range tests {
		tt := tt 
		t.Run(tt.name, func(t *testing.T) {
			err := storage.Allocate(tt.port)
			if (err == nil) != (tt.errMsg == "") {
				t.Fatalf("Error expected %v, received %v", tt.errMsg, err)
			}
			if err != nil && err.Error() != tt.errMsg {
				t.Fatalf("Error message expected %v, received %v", tt.errMsg, err)
			}
		})
	}
}
func TestAllocate ( t * testing . T ) { _ , storage , _ , si , destroyFunc := newStorage ( t ) defer destroyFunc ( ) if err := si . Create ( context . TODO ( ) , key ( ) , validNewRangeAllocation ( ) , nil , 0 ) ; err != nil { t . Fatalf ( " " , err ) } tests := [ ] struct { name string port int errMsg string } { { name : " " , port : basePortRange , errMsg : " " , } , { name : " " , port : basePortRange + sizePortRange - 1 , errMsg : " " , } , { name : " " , port : basePortRange - 1 , errMsg : fmt . Sprintf ( " " , basePortRange , basePortRange + sizePortRange - 1 ) , } , { name : " " , port : basePortRange + sizePortRange , errMsg : fmt . Sprintf ( " " , basePortRange , basePortRange + sizePortRange - 1 ) , } , { name : " " , port : - 2 , errMsg : fmt . Sprintf ( " " , basePortRange , basePortRange + sizePortRange - 1 ) , } , } for _ , tt := range tests { tt := tt t . Run ( tt . name , func ( t * testing . T ) { err := storage . Allocate ( tt . port ) if ( err == nil ) != ( tt . errMsg == " " ) { t . Fatalf ( " " , tt . errMsg , err ) } if err != nil && err . Error ( ) != tt . errMsg { t . Fatalf ( " " , tt . errMsg , err ) } } ) } }
TestAllocate fails to allocate ports out of the valid port range
TestAllocate fails to allocate ports out of the valid port range
// NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables