-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make tests backwards compatible with nerdctl v1 (#212)
Signed-off-by: Austin Vazquez <[email protected]>
- Loading branch information
1 parent
877cb84
commit 9f5e817
Showing
6 changed files
with
210 additions
and
5 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
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,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package option | ||
|
||
import "regexp" | ||
|
||
const ( | ||
nerdctl1xx = "1.x.x" | ||
nerdctl2xx = "2.x.x" | ||
defaultNerdctlVersion = nerdctl2xx | ||
) | ||
|
||
var ( | ||
nerdctl1xxRegex = regexp.MustCompile(`^1\.[x0-9]+\.[x0-9]+`) | ||
nerdctl2xxRegex = regexp.MustCompile(`^2\.[x0-9]+\.[x0-9]+`) | ||
) | ||
|
||
func isNerdctl1xx(version string) bool { | ||
return nerdctl1xxRegex.MatchString(version) | ||
} | ||
|
||
func isNerdctl2xx(version string) bool { | ||
return nerdctl2xxRegex.MatchString(version) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package option | ||
|
||
import "testing" | ||
|
||
func TestSupportsEnvVarPassthrough(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
mods []Modifier | ||
assert func(*testing.T, *Option) | ||
}{ | ||
{ | ||
name: "IsEnvVarPassthroughByDefault", | ||
mods: []Modifier{}, | ||
assert: func(t *testing.T, uut *Option) { | ||
if !uut.SupportsEnvVarPassthrough() { | ||
t.Fatal("expected SupportsEnvVarPassthrough to be true") | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "IsNotEnvVarPassthrough", | ||
mods: []Modifier{ | ||
WithNoEnvironmentVariablePassthrough(), | ||
}, | ||
assert: func(t *testing.T, uut *Option) { | ||
if uut.SupportsEnvVarPassthrough() { | ||
t.Fatal("expected SupportsEnvVarPassthrough to be false") | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
uut, err := New([]string{"nerdctl"}, test.mods...) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
test.assert(t, uut) | ||
}) | ||
} | ||
} | ||
|
||
func TestNerdctlVersion(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
mods []Modifier | ||
assert func(*testing.T, *Option) | ||
}{ | ||
{ | ||
name: "IsNerdctlV2ByDefault", | ||
mods: []Modifier{}, | ||
assert: func(t *testing.T, uut *Option) { | ||
if !uut.IsNerdctlV2() { | ||
t.Fatal("expected IsNerdctlV2 to be true") | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "IsNerdctlV1", | ||
mods: []Modifier{ | ||
WithNerdctlVersion("1.7.7"), | ||
}, | ||
assert: func(t *testing.T, uut *Option) { | ||
if !uut.IsNerdctlV1() { | ||
t.Fatal("expected IsNerdctlV1 to be true") | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "IsNerdctlV2", | ||
mods: []Modifier{ | ||
WithNerdctlVersion("2.0.2"), | ||
}, | ||
assert: func(t *testing.T, uut *Option) { | ||
if !uut.IsNerdctlV2() { | ||
t.Fatal("expected IsNerdctlV2 to be true") | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "IsPatchedNerdctlV2", | ||
mods: []Modifier{ | ||
WithNerdctlVersion("2.0.2.m"), | ||
}, | ||
assert: func(t *testing.T, uut *Option) { | ||
if !uut.IsNerdctlV2() { | ||
t.Fatal("expected IsNerdctlV2 to be true") | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
uut, err := New([]string{"nerdctl"}, test.mods...) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
test.assert(t, uut) | ||
}) | ||
} | ||
} |
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