package host import ( "strings" "testing" "github.com/carlosframework/platform/internal/runs" ) // A service's run reads as the service's in `carlos logs`: the person it // named appears only as the service's statement, never as who ran it // (service runs spec ยง2). func TestRunStartedLineForAServicesRun(t *testing.T) { req := runs.Request{ID: "r1", By: "service:bab/ci", ByService: "ci", ByCredential: "c0ffee", OnBehalfOf: "paul@example.com", Argv: []string{"import", "classic", "--token", "s3cret"}} got := runStartedLine(req) if want := "run r1 started by service ci for paul@example.com (as stated by the service)"; got != want { t.Fatalf("got %q, want %q", got, want) } if strings.Contains(got, "by paul@example.com") || strings.Contains(got, "c0ffee") { t.Fatalf("%q presents the person as the actor or shows the credential id", got) } for _, a := range req.Argv { if strings.Contains(got, a) { t.Fatalf("%q carries the argument %q", got, a) } } req.OnBehalfOf = "" if got, want := runStartedLine(req), "run r1 started by service ci (scheduled)"; got != want { t.Fatalf("scheduled: got %q, want %q", got, want) } }