2015-01-25 06:32:33 +03:00
|
|
|
// Copyright 2015 CoreOS, Inc.
|
|
|
|
//
|
|
|
|
// 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.
|
2014-10-18 02:36:22 +04:00
|
|
|
|
2014-06-25 04:46:06 +04:00
|
|
|
package initialize
|
|
|
|
|
2014-09-22 03:46:58 +04:00
|
|
|
import (
|
2015-01-23 04:35:39 +03:00
|
|
|
"net"
|
2014-09-22 03:46:58 +04:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2015-01-23 04:35:39 +03:00
|
|
|
"github.com/coreos/coreos-cloudinit/datasource"
|
2014-09-22 03:46:58 +04:00
|
|
|
)
|
2014-06-25 04:46:06 +04:00
|
|
|
|
|
|
|
func TestExtractIPsFromMetadata(t *testing.T) {
|
|
|
|
for i, tt := range []struct {
|
2015-01-23 04:35:39 +03:00
|
|
|
in datasource.Metadata
|
2014-06-25 04:46:06 +04:00
|
|
|
out map[string]string
|
|
|
|
}{
|
|
|
|
{
|
2015-01-23 04:35:39 +03:00
|
|
|
datasource.Metadata{
|
|
|
|
PublicIPv4: net.ParseIP("12.34.56.78"),
|
|
|
|
PrivateIPv4: net.ParseIP("1.2.3.4"),
|
|
|
|
PublicIPv6: net.ParseIP("1234::"),
|
|
|
|
PrivateIPv6: net.ParseIP("5678::"),
|
|
|
|
},
|
2014-09-11 19:35:09 +04:00
|
|
|
map[string]string{"$public_ipv4": "12.34.56.78", "$private_ipv4": "1.2.3.4", "$public_ipv6": "1234::", "$private_ipv6": "5678::"},
|
2014-06-25 04:46:06 +04:00
|
|
|
},
|
|
|
|
} {
|
2015-01-23 04:35:39 +03:00
|
|
|
got := ExtractIPsFromMetadata(tt.in)
|
2014-06-25 04:46:06 +04:00
|
|
|
if !reflect.DeepEqual(got, tt.out) {
|
|
|
|
t.Errorf("case %d: got %s, want %s", i, got, tt.out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|