mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(cli): display devcontainers in show command (#16515)
Displays running devcontainers into the `coder show` CLI command.
This commit is contained in:
@@ -8,9 +8,14 @@ import (
|
||||
|
||||
// Subset returns true if all the keys of a are present
|
||||
// in b and have the same values.
|
||||
// If the corresponding value of a[k] is the zero value in
|
||||
// b, Subset will skip comparing that value.
|
||||
// This allows checking for the presence of map keys.
|
||||
func Subset[T, U comparable](a, b map[T]U) bool {
|
||||
var uz U
|
||||
for ka, va := range a {
|
||||
if vb, ok := b[ka]; !ok || va != vb {
|
||||
ignoreZeroValue := va == uz
|
||||
if vb, ok := b[ka]; !ok || (!ignoreZeroValue && va != vb) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ func TestSubset(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for idx, tc := range []struct {
|
||||
a map[string]string
|
||||
b map[string]string
|
||||
a map[string]string
|
||||
b map[string]string
|
||||
// expected value from Subset
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
@@ -50,6 +51,24 @@ func TestSubset(t *testing.T) {
|
||||
b: map[string]string{"a": "1", "b": "3"},
|
||||
expected: false,
|
||||
},
|
||||
// Zero value
|
||||
{
|
||||
a: map[string]string{"a": "1", "b": ""},
|
||||
b: map[string]string{"a": "1", "b": "3"},
|
||||
expected: true,
|
||||
},
|
||||
// Zero value, but the other way round
|
||||
{
|
||||
a: map[string]string{"a": "1", "b": "3"},
|
||||
b: map[string]string{"a": "1", "b": ""},
|
||||
expected: false,
|
||||
},
|
||||
// Both zero values
|
||||
{
|
||||
a: map[string]string{"a": "1", "b": ""},
|
||||
b: map[string]string{"a": "1", "b": ""},
|
||||
expected: true,
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
t.Run("#"+strconv.Itoa(idx), func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user