| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/runs" |
| 8 | ) |
| 9 | |
| 10 | // A service's run reads as the service's in `carlos logs`: the person it |
| 11 | // named appears only as the service's statement, never as who ran it |
| 12 | // (service runs spec §2). |
| 13 | func TestRunStartedLineForAServicesRun(t *testing.T) { |
| 14 | req := runs.Request{ID: "r1", By: "service:bab/ci", ByService: "ci", ByCredential: "c0ffee", OnBehalfOf: "paul@example.com", |
| 15 | Argv: []string{"import", "classic", "--token", "s3cret"}} |
| 16 | got := runStartedLine(req) |
| 17 | if want := "run r1 started by service ci for paul@example.com (as stated by the service)"; got != want { |
| 18 | t.Fatalf("got %q, want %q", got, want) |
| 19 | } |
| 20 | if strings.Contains(got, "by paul@example.com") || strings.Contains(got, "c0ffee") { |
| 21 | t.Fatalf("%q presents the person as the actor or shows the credential id", got) |
| 22 | } |
| 23 | for _, a := range req.Argv { |
| 24 | if strings.Contains(got, a) { |
| 25 | t.Fatalf("%q carries the argument %q", got, a) |
| 26 | } |
| 27 | } |
| 28 | req.OnBehalfOf = "" |
| 29 | if got, want := runStartedLine(req), "run r1 started by service ci (scheduled)"; got != want { |
| 30 | t.Fatalf("scheduled: got %q, want %q", got, want) |
| 31 | } |
| 32 | } |
| 33 | |