From 46b0ad8cf5c1921c3411cca18a812984407c984b Mon Sep 17 00:00:00 2001 From: krrrr38 Date: Mon, 16 Jan 2023 06:54:09 +0900 Subject: [PATCH] add web_templates render tests --- server/controllers/templates/web_templates.go | 1 - .../templates/web_templates_test.go | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 server/controllers/templates/web_templates_test.go diff --git a/server/controllers/templates/web_templates.go b/server/controllers/templates/web_templates.go index 6dc2a567a0..103114e622 100644 --- a/server/controllers/templates/web_templates.go +++ b/server/controllers/templates/web_templates.go @@ -242,7 +242,6 @@ type LockDetailData struct { PullRequestLink string LockedBy string Workspace string - Time time.Time AtlantisVersion string // CleanedBasePath is the path Atlantis is accessible at externally. If // not using a path-based proxy, this will be an empty string. Never ends diff --git a/server/controllers/templates/web_templates_test.go b/server/controllers/templates/web_templates_test.go new file mode 100644 index 0000000000..091f3db275 --- /dev/null +++ b/server/controllers/templates/web_templates_test.go @@ -0,0 +1,79 @@ +package templates + +import ( + "io" + "testing" + "time" + + . "github.com/runatlantis/atlantis/testing" +) + +func TestIndexTemplate(t *testing.T) { + err := IndexTemplate.Execute(io.Discard, IndexData{ + Locks: []LockIndexData{ + { + LockPath: "lock path", + RepoFullName: "repo full name", + PullNum: 1, + Path: "path", + Workspace: "workspace", + Time: time.Now(), + TimeFormatted: "02-01-2006 15:04:05", + }, + }, + ApplyLock: ApplyLockData{ + Locked: true, + Time: time.Now(), + TimeFormatted: "02-01-2006 15:04:05", + }, + AtlantisVersion: "v0.0.0", + CleanedBasePath: "/path", + }) + Ok(t, err) +} + +func TestLockTemplate(t *testing.T) { + err := LockTemplate.Execute(io.Discard, LockDetailData{ + LockKeyEncoded: "lock key encoded", + LockKey: "lock key", + PullRequestLink: "https://example.com", + LockedBy: "locked by", + Workspace: "workspace", + AtlantisVersion: "v0.0.0", + CleanedBasePath: "/path", + RepoOwner: "repo owner", + RepoName: "repo name", + }) + Ok(t, err) +} + +func TestProjectJobsTemplate(t *testing.T) { + err := ProjectJobsTemplate.Execute(io.Discard, ProjectJobData{ + AtlantisVersion: "v0.0.0", + ProjectPath: "project path", + CleanedBasePath: "/path", + }) + Ok(t, err) +} + +func TestProjectJobsErrorTemplate(t *testing.T) { + err := ProjectJobsTemplate.Execute(io.Discard, ProjectJobsError{ + AtlantisVersion: "v0.0.0", + ProjectPath: "project path", + CleanedBasePath: "/path", + }) + Ok(t, err) +} + +func TestGithubAppSetupTemplate(t *testing.T) { + err := GithubAppSetupTemplate.Execute(io.Discard, GithubSetupData{ + Target: "target", + Manifest: "manifest", + ID: 1, + Key: "key", + WebhookSecret: "webhook secret", + URL: "https://example.com", + CleanedBasePath: "/path", + }) + Ok(t, err) +}