2022-03-22 11:03:15 -04:00
|
|
|
package gcp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIDs(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
testState := testInstances()
|
2022-04-26 10:54:05 -04:00
|
|
|
wantIDs := []string{"id-9", "id-10", "id-11", "id-12"}
|
|
|
|
assert.ElementsMatch(wantIDs, testState.IDs())
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublicIPs(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
testState := testInstances()
|
2022-04-26 10:54:05 -04:00
|
|
|
wantIPs := []string{"192.0.2.1", "192.0.2.3", "192.0.2.5", "192.0.2.7"}
|
|
|
|
assert.ElementsMatch(wantIPs, testState.PublicIPs())
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPrivateIPs(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
testState := testInstances()
|
2022-04-26 10:54:05 -04:00
|
|
|
wantIPs := []string{"192.0.2.2", "192.0.2.4", "192.0.2.6", "192.0.2.8"}
|
|
|
|
assert.ElementsMatch(wantIPs, testState.PrivateIPs())
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOne(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
testState := testInstances()
|
|
|
|
id, instance, err := testState.GetOne()
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Contains(testState, id)
|
|
|
|
assert.Equal(testState[id], instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOthers(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
testCases := testInstances().IDs()
|
|
|
|
|
|
|
|
for _, id := range testCases {
|
|
|
|
others := testInstances().GetOthers(id)
|
|
|
|
assert.NotContains(others, id)
|
2022-04-26 10:54:05 -04:00
|
|
|
wantInstances := testInstances()
|
|
|
|
delete(wantInstances, id)
|
|
|
|
assert.ElementsMatch(others.IDs(), wantInstances.IDs())
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testInstances() Instances {
|
|
|
|
return Instances{
|
|
|
|
"id-9": {
|
|
|
|
PublicIP: "192.0.2.1",
|
|
|
|
PrivateIP: "192.0.2.2",
|
|
|
|
},
|
|
|
|
"id-10": {
|
|
|
|
PublicIP: "192.0.2.3",
|
|
|
|
PrivateIP: "192.0.2.4",
|
|
|
|
},
|
|
|
|
"id-11": {
|
|
|
|
PublicIP: "192.0.2.5",
|
|
|
|
PrivateIP: "192.0.2.6",
|
|
|
|
},
|
|
|
|
"id-12": {
|
|
|
|
PublicIP: "192.0.2.7",
|
|
|
|
PrivateIP: "192.0.2.8",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|