Skip to content

feat(provisionersdk): allow variadic tags in provisionersdk.MutateTags #15518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
i keep forgetting about util/slice
  • Loading branch information
johnstcn committed Nov 14, 2024
commit 905e66e057c1f7ae1973e4add3dce1894e182533
31 changes: 14 additions & 17 deletions provisionersdk/provisionertags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provisionersdk_test
import (
"testing"

"github.com/coder/coder/v2/coderd/util/slice"
"github.com/coder/coder/v2/provisionersdk"

"github.com/google/uuid"
Expand All @@ -23,7 +24,7 @@ func TestMutateTags(t *testing.T) {
{
name: "nil tags",
userID: uuid.Nil,
tags: mapslice(nil),
tags: []map[string]string{nil},
want: map[string]string{
provisionersdk.TagScope: provisionersdk.ScopeOrganization,
provisionersdk.TagOwner: "",
Expand All @@ -32,15 +33,15 @@ func TestMutateTags(t *testing.T) {
{
name: "empty tags",
userID: uuid.Nil,
tags: mapslice(map[string]string{}),
tags: slice.New(map[string]string{}),
want: map[string]string{
provisionersdk.TagScope: provisionersdk.ScopeOrganization,
provisionersdk.TagOwner: "",
},
},
{
name: "user scope",
tags: mapslice(
tags: slice.New(
map[string]string{provisionersdk.TagScope: provisionersdk.ScopeUser},
),
userID: testUserID,
Expand All @@ -51,7 +52,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "organization scope",
tags: mapslice(
tags: slice.New(
map[string]string{provisionersdk.TagScope: provisionersdk.ScopeOrganization},
),
userID: testUserID,
Expand All @@ -62,7 +63,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "organization scope with owner",
tags: mapslice(
tags: slice.New(
map[string]string{
provisionersdk.TagScope: provisionersdk.ScopeOrganization,
provisionersdk.TagOwner: testUserID.String(),
Expand All @@ -76,7 +77,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "owner tag with no other context",
tags: mapslice(
tags: slice.New(
map[string]string{
provisionersdk.TagOwner: testUserID.String(),
},
Expand All @@ -89,7 +90,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "invalid scope",
tags: mapslice(
tags: slice.New(
map[string]string{provisionersdk.TagScope: "360noscope"},
),
userID: testUserID,
Expand All @@ -100,7 +101,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "merge two empty maps",
tags: mapslice(
tags: slice.New(
map[string]string{},
map[string]string{},
),
Expand All @@ -112,7 +113,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "merge empty map with non-empty map",
tags: mapslice(
tags: slice.New(
map[string]string{},
map[string]string{"foo": "bar"},
),
Expand All @@ -125,7 +126,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "merge non-empty map with empty map",
tags: mapslice(
tags: slice.New(
map[string]string{"foo": "bar"},
map[string]string{},
),
Expand All @@ -138,7 +139,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "merge map with same map",
tags: mapslice(
tags: slice.New(
map[string]string{"foo": "bar"},
map[string]string{"foo": "bar"},
),
Expand All @@ -151,7 +152,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "merge map with override",
tags: mapslice(
tags: slice.New(
map[string]string{"foo": "bar"},
map[string]string{"foo": "baz"},
),
Expand All @@ -164,7 +165,7 @@ func TestMutateTags(t *testing.T) {
},
{
name: "do not override empty in second map",
tags: mapslice(
tags: slice.New(
map[string]string{"foo": "bar"},
map[string]string{"foo": ""},
),
Expand All @@ -184,7 +185,3 @@ func TestMutateTags(t *testing.T) {
})
}
}

func mapslice(m ...map[string]string) []map[string]string {
return m
}
Loading