2019-04-22 21:35:39 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-19 12:21:03 +00:00
|
|
|
// TODO: Add more test tuples to test out other edge conditions.
|
2019-04-22 21:35:39 +00:00
|
|
|
var testData = []testTuple{
|
|
|
|
{
|
|
|
|
vID: CSIIdentifier{
|
2019-05-28 19:03:18 +00:00
|
|
|
LocationID: 0xffff,
|
2024-03-14 09:40:49 +00:00
|
|
|
encodingVersion: 0xffff,
|
2019-04-22 21:35:39 +00:00
|
|
|
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) {
|
2021-06-02 09:55:53 +00:00
|
|
|
t.Parallel()
|
2019-04-22 21:35:39 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|