mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
32839948ef
The internal/ directory in Go has a special meaning, and indicates that those packages are not meant for external consumption. Ceph-CSI does provide public APIs for other projects to consume. There is no plan to keep the API of the internally used packages stable. Closes: #903 Signed-off-by: Niels de Vos <ndevos@redhat.com>
96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
/*
|
|
Copyright 2019 Ceph-CSI authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package util
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
type testTuple struct {
|
|
vID CSIIdentifier
|
|
composedVolID string
|
|
wantEnc bool
|
|
wantEncError bool
|
|
wantDec bool
|
|
wantDecError bool
|
|
}
|
|
|
|
// TODO: Add more test tuples to test out other edge conditions
|
|
var testData = []testTuple{
|
|
{
|
|
vID: CSIIdentifier{
|
|
LocationID: 0xffff,
|
|
EncodingVersion: 0xffff,
|
|
ClusterID: "01616094-9d93-4178-bf45-c7eac19e8b15",
|
|
ObjectUUID: "00000000-1111-2222-bbbb-cacacacacaca",
|
|
},
|
|
composedVolID: "ffff-0024-01616094-9d93-4178-bf45-c7eac19e8b15-000000000000ffff-00000000-1111-2222-bbbb-cacacacacaca",
|
|
wantEnc: true,
|
|
wantEncError: false,
|
|
wantDec: true,
|
|
wantDecError: false,
|
|
},
|
|
}
|
|
|
|
func TestComposeDecomposeID(t *testing.T) {
|
|
var (
|
|
err error
|
|
viDecompose CSIIdentifier
|
|
composedVolID string
|
|
)
|
|
|
|
for _, test := range testData {
|
|
if test.wantEnc {
|
|
composedVolID, err = test.vID.ComposeCSIID()
|
|
|
|
if err != nil && !test.wantEncError {
|
|
t.Errorf("Composing failed: want (%#v), got (%#v %#v)",
|
|
test, composedVolID, err)
|
|
}
|
|
|
|
if err == nil && test.wantEncError {
|
|
t.Errorf("Composing failed: want (%#v), got (%#v %#v)",
|
|
test, composedVolID, err)
|
|
}
|
|
|
|
if !test.wantEncError && err == nil && composedVolID != test.composedVolID {
|
|
t.Errorf("Composing failed: want (%#v), got (%#v %#v)",
|
|
test, composedVolID, err)
|
|
}
|
|
}
|
|
|
|
if test.wantDec {
|
|
err = viDecompose.DecomposeCSIID(test.composedVolID)
|
|
|
|
if err != nil && !test.wantDecError {
|
|
t.Errorf("Decomposing failed: want (%#v), got (%#v %#v)",
|
|
test, viDecompose, err)
|
|
}
|
|
|
|
if err == nil && test.wantDecError {
|
|
t.Errorf("Decomposing failed: want (%#v), got (%#v %#v)",
|
|
test, viDecompose, err)
|
|
}
|
|
|
|
if !test.wantDecError && err == nil && viDecompose != test.vID {
|
|
t.Errorf("Decomposing failed: want (%#v), got (%#v %#v)",
|
|
test, viDecompose, err)
|
|
}
|
|
}
|
|
}
|
|
}
|