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) {
|
||||
|
||||
@@ -1076,7 +1076,8 @@ func TestWorkspaceAgentContainers(t *testing.T) {
|
||||
pool, err := dockertest.NewPool("")
|
||||
require.NoError(t, err, "Could not connect to docker")
|
||||
testLabels := map[string]string{
|
||||
"com.coder.test": uuid.New().String(),
|
||||
"com.coder.test": uuid.New().String(),
|
||||
"com.coder.empty": "",
|
||||
}
|
||||
ct, err := pool.RunWithOptions(&dockertest.RunOptions{
|
||||
Repository: "busybox",
|
||||
@@ -1097,7 +1098,10 @@ func TestWorkspaceAgentContainers(t *testing.T) {
|
||||
Repository: "busybox",
|
||||
Tag: "latest",
|
||||
Cmd: []string{"sleep", "infinity"},
|
||||
Labels: map[string]string{"com.coder.test": "ignoreme"},
|
||||
Labels: map[string]string{
|
||||
"com.coder.test": "ignoreme",
|
||||
"com.coder.empty": "",
|
||||
},
|
||||
}, func(config *docker.HostConfig) {
|
||||
config.AutoRemove = true
|
||||
config.RestartPolicy = docker.RestartPolicy{Name: "no"}
|
||||
|
||||
Reference in New Issue
Block a user