mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 13:55:55 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package agent
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAgentRetryNewDiscover(t *testing.T) {
|
|
d, err := newDiscover()
|
|
require.NoError(t, err)
|
|
expected := []string{
|
|
"aliyun", "aws", "azure", "digitalocean", "gce", "hcp", "k8s", "linode",
|
|
"mdns", "os", "packet", "scaleway", "softlayer", "tencentcloud",
|
|
"triton", "vsphere",
|
|
}
|
|
require.Equal(t, expected, d.Names())
|
|
}
|
|
|
|
func TestAgentRetryJoinAddrs(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("too slow for testing.Short")
|
|
}
|
|
|
|
d, err := newDiscover()
|
|
require.NoError(t, err)
|
|
|
|
tests := []struct {
|
|
name string
|
|
input []string
|
|
expected []string
|
|
}{
|
|
{"handles nil", nil, []string{}},
|
|
{"handles empty input", []string{}, []string{}},
|
|
{"handles one element",
|
|
[]string{"192.168.0.12"},
|
|
[]string{"192.168.0.12"},
|
|
},
|
|
{"handles two elements",
|
|
[]string{"192.168.0.12", "192.168.0.13"},
|
|
[]string{"192.168.0.12", "192.168.0.13"},
|
|
},
|
|
{"tries to resolve aws things, which fails but that is fine",
|
|
[]string{"192.168.0.12", "provider=aws region=eu-west-1 tag_key=consul tag_value=tag access_key_id=a secret_access_key=a"},
|
|
[]string{"192.168.0.12"},
|
|
},
|
|
}
|
|
for i, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
logger := testutil.LoggerWithOutput(t, &buf)
|
|
|
|
output := retryJoinAddrs(d, retryJoinSerfVariant, "LAN", test.input, logger)
|
|
bufout := buf.String()
|
|
require.Equal(t, test.expected, output, bufout)
|
|
if i == 4 {
|
|
require.Contains(t, bufout, `Using provider "aws"`)
|
|
}
|
|
})
|
|
}
|
|
t.Run("handles nil discover", func(t *testing.T) {
|
|
require.Equal(t, []string{}, retryJoinAddrs(nil, retryJoinSerfVariant, "LAN", []string{"a"}, nil))
|
|
})
|
|
}
|