54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes 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 azure
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetScaleSetVMInstanceID(t *testing.T) {
|
|
tests := []struct {
|
|
msg string
|
|
machineName string
|
|
expectError bool
|
|
expectedInstanceID string
|
|
}{{
|
|
msg: "invalid vmss instance name",
|
|
machineName: "vmvm",
|
|
expectError: true,
|
|
},
|
|
{
|
|
msg: "valid vmss instance name",
|
|
machineName: "vm00000Z",
|
|
expectError: false,
|
|
expectedInstanceID: "35",
|
|
},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
instanceID, err := getScaleSetVMInstanceID(test.machineName)
|
|
if test.expectError {
|
|
assert.Error(t, err, fmt.Sprintf("TestCase[%d]: %s", i, test.msg))
|
|
} else {
|
|
assert.Equal(t, test.expectedInstanceID, instanceID, fmt.Sprintf("TestCase[%d]: %s", i, test.msg))
|
|
}
|
|
}
|
|
}
|