-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v9] Regenerate host UUID of node if host_uuid is empty (#12222)
This change allows nodes to regenerate their UUID if the host_uuid file exists but is empty.
- Loading branch information
Showing
5 changed files
with
324 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2022 Gravitational, 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. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSliceContainsStr(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
slice []string | ||
target string | ||
wantContains bool | ||
}{ | ||
{name: "does contain", slice: []string{"two", "one"}, target: "one", wantContains: true}, | ||
{name: "does not contain", slice: []string{"two", "one"}, target: "five", wantContains: false}, | ||
{name: "empty slice", slice: nil, target: "one", wantContains: false}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
require.Equal(t, tc.wantContains, SliceContainsStr(tc.slice, tc.target)) | ||
}) | ||
} | ||
} | ||
|
||
func TestDeduplicate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in, expected []string | ||
}{ | ||
{name: "empty slice", in: []string{}, expected: []string{}}, | ||
{name: "slice with unique elements", in: []string{"a", "b"}, expected: []string{"a", "b"}}, | ||
{name: "slice with duplicate elements", in: []string{"a", "b", "b", "a", "c"}, expected: []string{"a", "b", "c"}}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
require.Equal(t, tc.expected, Deduplicate(tc.in)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,16 @@ limitations under the License. | |
package utils | ||
|
||
import ( | ||
"gopkg.in/check.v1" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func (s *UtilsSuite) TestProxyJumpParsing(c *check.C) { | ||
func TestProxyJumpParsing(t *testing.T) { | ||
type tc struct { | ||
in string | ||
out []JumpHost | ||
err error | ||
} | ||
testCases := []tc{ | ||
{ | ||
|
@@ -56,14 +58,11 @@ func (s *UtilsSuite) TestProxyJumpParsing(c *check.C) { | |
out: []JumpHost{{Username: "[email protected]", Addr: NetAddr{Addr: "[::1]:7777", AddrNetwork: "tcp"}}, {Username: "bob@localhost", Addr: NetAddr{Addr: "localhost", AddrNetwork: "tcp"}}}, | ||
}, | ||
} | ||
for i, tc := range testCases { | ||
comment := check.Commentf("Test case %v: %q", i, tc.in) | ||
re, err := ParseProxyJump(tc.in) | ||
if tc.err == nil { | ||
c.Assert(err, check.IsNil, comment) | ||
c.Assert(re, check.DeepEquals, tc.out) | ||
} else { | ||
c.Assert(err, check.FitsTypeOf, tc.err) | ||
} | ||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("%q", tc.in), func(t *testing.T) { | ||
re, err := ParseProxyJump(tc.in) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.out, re) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.