Skip to content

Commit

Permalink
Merge pull request #574 from shaneutt/shaneutt/remove-hardcoded-years…
Browse files Browse the repository at this point in the history
…-in-tests

Remove hardcoded years in scaffold tests
  • Loading branch information
k8s-ci-robot authored Jan 25, 2019
2 parents 64ddaf7 + 8c5c6c9 commit f76146e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/scaffold/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -18,11 +20,13 @@ var _ = Describe("Project", func() {
var result *scaffoldtest.TestResult
var writeToPath, goldenPath string
var s *scaffold.Scaffold
var year string

JustBeforeEach(func() {
s, result = scaffoldtest.NewTestScaffold(writeToPath, goldenPath)
s.BoilerplateOptional = true
s.ProjectOptional = true
year = strconv.Itoa(time.Now().Year())
})

Describe("scaffolding a boilerplate file", func() {
Expand All @@ -32,7 +36,7 @@ var _ = Describe("Project", func() {
})

It("should match the golden file", func() {
instance := &Boilerplate{Year: "2019", License: "apache2", Owner: "The Kubernetes authors"}
instance := &Boilerplate{Year: year, License: "apache2", Owner: "The Kubernetes authors"}
Expect(s.Execute(input.Options{}, instance)).NotTo(HaveOccurred())
Expect(result.Actual.String()).To(BeEquivalentTo(result.Golden))
})
Expand All @@ -45,15 +49,15 @@ var _ = Describe("Project", func() {

Context("for apache2", func() {
It("should write the apache2 boilerplate with specified owners", func() {
instance := &Boilerplate{Year: "2019", Owner: "Example Owners"}
instance := &Boilerplate{Year: year, Owner: "Example Owners"}
Expect(s.Execute(input.Options{}, instance)).NotTo(HaveOccurred())
e := strings.Replace(
result.Golden, "The Kubernetes authors", "Example Owners", -1)
Expect(result.Actual.String()).To(BeEquivalentTo(e))
})

It("should use apache2 as the default", func() {
instance := &Boilerplate{Year: "2019", Owner: "The Kubernetes authors"}
instance := &Boilerplate{Year: year, Owner: "The Kubernetes authors"}
Expect(s.Execute(input.Options{}, instance)).NotTo(HaveOccurred())
Expect(result.Actual.String()).To(BeEquivalentTo(result.Golden))
})
Expand All @@ -62,11 +66,11 @@ var _ = Describe("Project", func() {
Context("for none", func() {
It("should write the empty boilerplate", func() {
// Scaffold a boilerplate file
instance := &Boilerplate{Year: "2019", License: "none", Owner: "Example Owners"}
instance := &Boilerplate{Year: year, License: "none", Owner: "Example Owners"}
Expect(s.Execute(input.Options{}, instance)).NotTo(HaveOccurred())
Expect(result.Actual.String()).To(BeEquivalentTo(`/*
Copyright 2019 Example Owners.
*/`))
Expect(result.Actual.String()).To(BeEquivalentTo(fmt.Sprintf(`/*
Copyright %s Example Owners.
*/`, year)))
})
})

Expand Down

0 comments on commit f76146e

Please sign in to comment.