- Notifications
You must be signed in to change notification settings - Fork928
chore: update provisioner tag documentation with suggestions from #12315#12347
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
chore(coderd): add more test cases to TestAcquirer_MatchTags, generat…
…e table for docs
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commita65b90b09ed67699d60c91127ace47f7aa49eb95
There are no files selected for viewing
151 changes: 121 additions & 30 deletionscoderd/provisionerdserver/acquirer_test.go
This file contains hidden or 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 |
---|---|---|
@@ -4,6 +4,8 @@ import ( | ||
"context" | ||
"database/sql" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"sync" | ||
"testing" | ||
"time" | ||
@@ -54,7 +56,7 @@ func TestAcquirer_Single(t *testing.T) { | ||
workerID := uuid.New() | ||
pt := []database.ProvisionerType{database.ProvisionerTypeEcho} | ||
tags := provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
} | ||
acquiree := newTestAcquiree(t, workerID, pt, tags) | ||
jobID := uuid.New() | ||
@@ -82,7 +84,7 @@ func TestAcquirer_MultipleSameDomain(t *testing.T) { | ||
workerIDs := make(map[uuid.UUID]bool) | ||
pt := []database.ProvisionerType{database.ProvisionerTypeEcho} | ||
tags := provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
} | ||
for i := 0; i < 10; i++ { | ||
wID := uuid.New() | ||
@@ -125,7 +127,7 @@ func TestAcquirer_WaitsOnNoJobs(t *testing.T) { | ||
workerID := uuid.New() | ||
pt := []database.ProvisionerType{database.ProvisionerTypeEcho} | ||
tags := provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
} | ||
acquiree := newTestAcquiree(t, workerID, pt, tags) | ||
jobID := uuid.New() | ||
@@ -147,10 +149,10 @@ func TestAcquirer_WaitsOnNoJobs(t *testing.T) { | ||
"strong": "bad", | ||
}) | ||
postJob(t, ps, database.ProvisionerTypeEcho, provisionerdserver.Tags{ | ||
"environment": "fighters", | ||
}) | ||
postJob(t, ps, database.ProvisionerTypeTerraform, provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
}) | ||
acquiree.requireBlocked() | ||
@@ -176,7 +178,7 @@ func TestAcquirer_RetriesPending(t *testing.T) { | ||
workerID := uuid.New() | ||
pt := []database.ProvisionerType{database.ProvisionerTypeEcho} | ||
tags := provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
} | ||
acquiree := newTestAcquiree(t, workerID, pt, tags) | ||
jobID := uuid.New() | ||
@@ -268,7 +270,7 @@ func TestAcquirer_BackupPoll(t *testing.T) { | ||
workerID := uuid.New() | ||
pt := []database.ProvisionerType{database.ProvisionerTypeEcho} | ||
tags := provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
} | ||
acquiree := newTestAcquiree(t, workerID, pt, tags) | ||
jobID := uuid.New() | ||
@@ -294,7 +296,7 @@ func TestAcquirer_UnblockOnCancel(t *testing.T) { | ||
pt := []database.ProvisionerType{database.ProvisionerTypeEcho} | ||
worker0 := uuid.New() | ||
tags := provisionerdserver.Tags{ | ||
"environment": "on-prem", | ||
} | ||
acquiree0 := newTestAcquiree(t, worker0, pt, tags) | ||
worker1 := uuid.New() | ||
@@ -324,10 +326,7 @@ func TestAcquirer_MatchTags(t *testing.T) { | ||
t.Skip("skipping this test due to -short") | ||
} | ||
testCases := []struct { | ||
name string | ||
provisionerJobTags map[string]string | ||
acquireJobTags map[string]string | ||
@@ -341,69 +340,118 @@ func TestAcquirer_MatchTags(t *testing.T) { | ||
}, | ||
{ | ||
name: "untagged provisioner and tagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": ""}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "tagged provisioner and untagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": ""}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem"}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "tagged provisioner and tagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "tagged provisioner and double-tagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem", "datacenter": "chicago"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem"}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "double-tagged provisioner and tagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem", "datacenter": "chicago"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "double-tagged provisioner and double-tagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem", "datacenter": "chicago"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": "", "environment": "on-prem", "datacenter": "chicago"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner and untagged job", | ||
provisionerJobTags: map[string]string{"scope": "organization", "owner": ""}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner":"aaa"}, | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner and owner-scoped job", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner":"aaa"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner":"aaa"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner and different owner-scoped job", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner":"bbb"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner":"aaa"}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "org-scoped provisioner and owner-scoped job", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": ""}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner and org-scoped job with tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "organization", "owner": ""}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner with tags and owner-scoped job", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner and owner-scoped job with tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa"}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner with tags and owner-scoped job with tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner with multiple tags and owner-scoped job with tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem", "datacenter": "chicago"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner with tags and owner-scoped job with multiple tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem", "datacenter": "chicago"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem"}, | ||
expectAcquire: false, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner with tags and owner-scoped job with multiple tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem", "datacenter": "chicago"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem", "datacenter": "chicago"}, | ||
expectAcquire: true, | ||
}, | ||
{ | ||
name: "owner-scoped provisioner with tags and owner-scoped job with differing tags", | ||
provisionerJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem", "datacenter": "new_york"}, | ||
acquireJobTags: map[string]string{"scope": "owner", "owner": "aaa", "environment": "on-prem", "datacenter": "chicago"}, | ||
expectAcquire: false, | ||
}, | ||
} | ||
for _, tt := range testCases { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
ctx := testutil.Context(t, testutil.WaitShort/2) | ||
// NOTE: explicitly not using fake store for this test. | ||
db, ps := dbtestutil.NewDB(t) | ||
@@ -443,6 +491,43 @@ func TestAcquirer_MatchTags(t *testing.T) { | ||
} | ||
}) | ||
} | ||
t.Run("GenTable", func(t *testing.T) { | ||
t.Parallel() | ||
// Generate a table that can be copy-pasted into docs/admin/provisioners.md | ||
lines := []string{ | ||
"\n", | ||
"| Provisioner Tags | Job Tags | Can Run Job? |", | ||
"|------------------|----------|--------------|", | ||
} | ||
// turn the JSON map into k=v for readability | ||
kvs := func(m map[string]string) string { | ||
ss := make([]string, 0, len(m)) | ||
// always start with scope and owner | ||
ss = append(ss, "scope"+"="+m["scope"]) | ||
ss = append(ss, "owner"+"="+m["owner"]) | ||
for k, v := range m { | ||
if k == "scope" || k == "owner" { | ||
continue | ||
} | ||
if len(v) == 0 { | ||
v = `""` | ||
} | ||
ss = append(ss, k+"="+v) | ||
} | ||
return strings.Join(ss, " ") | ||
} | ||
for _, tt := range testCases { | ||
acquire := "✅" | ||
if !tt.expectAcquire { | ||
acquire = "❌" | ||
} | ||
s := fmt.Sprintf("| %s | %s | %s |", kvs(tt.acquireJobTags), kvs(tt.provisionerJobTags), acquire) | ||
lines = append(lines, s) | ||
} | ||
t.Logf("You can paste this into docs/admin/provisioners.md") | ||
t.Logf(strings.Join(lines, "\n")) | ||
}) | ||
} | ||
func postJob(t *testing.T, ps pubsub.Pubsub, pt database.ProvisionerType, tags provisionerdserver.Tags) { | ||
@@ -641,3 +726,9 @@ func (a *testAcquiree) requireCanceled(ctx context.Context) { | ||
a.t.Fatal("timed out waiting for AcquireJob") | ||
} | ||
} | ||
func jsonify(t *testing.T, m map[string]string) string { | ||
bs, err := json.Marshal(m) | ||
require.NoError(t, err) | ||
return string(bs) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.