Skip to content

Commit

Permalink
Stop using dot-imports in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Sep 7, 2023
1 parent b930449 commit 3976898
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 92 deletions.
20 changes: 10 additions & 10 deletions colorlogger/colorLogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package colorlogger_test
import (
"bytes"

. "github.com/cloudfoundry/stembuild/colorlogger"
"github.com/cloudfoundry/stembuild/colorlogger"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -13,45 +13,45 @@ var _ = Describe("Stdout", func() {
It("write debug output when log level is debug", func() {
buf := bytes.Buffer{}

Expect(DEBUG).To(Equal(0))
logger := ConstructLogger(DEBUG, false, &buf)
Expect(colorlogger.DEBUG).To(Equal(0))
logger := colorlogger.ConstructLogger(colorlogger.DEBUG, false, &buf)

message := "This is a test"

logger.Logf(DEBUG, message)
logger.Logf(colorlogger.DEBUG, message)
Expect(buf.String()).To(Equal("debug: " + message + "\n"))
})

It("write no debug output when log level is NONE", func() {
buf := bytes.Buffer{}

logger := ConstructLogger(NONE, false, &buf)
logger := colorlogger.ConstructLogger(colorlogger.NONE, false, &buf)

message := "This is a test"

logger.Logf(DEBUG, message)
logger.Logf(colorlogger.DEBUG, message)
Expect(buf.String()).To(BeEmpty())
})

It("write no none output when log level is NONE", func() {
buf := bytes.Buffer{}

logger := ConstructLogger(NONE, false, &buf)
logger := colorlogger.ConstructLogger(colorlogger.NONE, false, &buf)

message := "This is a test"

logger.Logf(NONE, message)
logger.Logf(colorlogger.NONE, message)
Expect(buf.String()).To(BeEmpty())
})

It("write colored debug output when log level is DEBUG and color is true", func() {
buf := bytes.Buffer{}

logger := ConstructLogger(DEBUG, true, &buf)
logger := colorlogger.ConstructLogger(colorlogger.DEBUG, true, &buf)

message := "This is a test"

logger.Logf(DEBUG, message)
logger.Logf(colorlogger.DEBUG, message)
Expect(buf.String()).To(Equal("\033[32mdebug:\033[0m " + message + "\n"))
})

Expand Down
8 changes: 4 additions & 4 deletions commandparser/construct_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package commandparser_test
import (
"path/filepath"

. "github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/commandparser"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -20,7 +20,7 @@ var _ = Describe("construct_helpers", func() {
dir := filepath.Join("..", "test", "constructData", "emptyDir")

It("should return false with no error", func() {
present, err := IsArtifactInDirectory(dir, filename)
present, err := commandparser.IsArtifactInDirectory(dir, filename)
Expect(err).ToNot(HaveOccurred())
Expect(present).To(BeFalse())
})
Expand All @@ -30,7 +30,7 @@ var _ = Describe("construct_helpers", func() {
dir := filepath.Join("..", "test", "constructData", "fullDir")

It("should return true with no error", func() {
present, err := IsArtifactInDirectory(dir, filename)
present, err := commandparser.IsArtifactInDirectory(dir, filename)
Expect(err).ToNot(HaveOccurred())
Expect(present).To(BeTrue())
})
Expand All @@ -42,7 +42,7 @@ var _ = Describe("construct_helpers", func() {
filename := "file"
It("should return an error", func() {
dir := filepath.Join("..", "test", "constructData", "notExist")
_, err := IsArtifactInDirectory(dir, filename)
_, err := commandparser.IsArtifactInDirectory(dir, filename)
Expect(err).To(HaveOccurred())
})
})
Expand Down
14 changes: 7 additions & 7 deletions commandparser/construct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"flag"

. "github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/commandparser/commandparserfakes"
"github.com/google/subcommands"

Expand All @@ -20,11 +20,11 @@ var _ = Describe("construct", func() {
Describe("SetFlags", func() {

var f *flag.FlagSet
var ConstrCmd *ConstructCmd
var ConstrCmd *commandparser.ConstructCmd

BeforeEach(func() {
f = flag.NewFlagSet("test", flag.ContinueOnError)
ConstrCmd = &ConstructCmd{}
ConstrCmd = &commandparser.ConstructCmd{}
ConstrCmd.SetFlags(f)
})

Expand Down Expand Up @@ -138,8 +138,8 @@ var _ = Describe("construct", func() {
Describe("Execute", func() {

var f *flag.FlagSet
var gf *GlobalFlags
var ConstrCmd *ConstructCmd
var gf *commandparser.GlobalFlags
var ConstrCmd *commandparser.ConstructCmd
var emptyContext context.Context

var fakeFactory *commandparserfakes.FakeVMPreparerFactory
Expand All @@ -150,7 +150,7 @@ var _ = Describe("construct", func() {

BeforeEach(func() {
f = flag.NewFlagSet("test", flag.ExitOnError)
gf = &GlobalFlags{false, false, false}
gf = &commandparser.GlobalFlags{false, false, false}

fakeFactory = &commandparserfakes.FakeVMPreparerFactory{}
fakeVmConstruct = &commandparserfakes.FakeVmConstruct{}
Expand All @@ -159,7 +159,7 @@ var _ = Describe("construct", func() {
fakeManagerFactory = &commandparserfakes.FakeManagerFactory{}
fakeFactory.VMPreparerReturns(fakeVmConstruct, nil)

ConstrCmd = NewConstructCmd(context.Background(), fakeFactory, fakeManagerFactory, fakeValidator, fakeMessenger)
ConstrCmd = commandparser.NewConstructCmd(context.Background(), fakeFactory, fakeManagerFactory, fakeValidator, fakeMessenger)
ConstrCmd.SetFlags(f)
ConstrCmd.GlobalFlags = gf
emptyContext = context.Background()
Expand Down
4 changes: 2 additions & 2 deletions commandparser/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"path"

. "github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/version"
"github.com/google/subcommands"
. "github.com/onsi/ginkgo/v2"
Expand All @@ -24,7 +24,7 @@ var _ = Describe("help", func() {
buf := bytes.Buffer{}
fs := flag.NewFlagSet(path.Base(os.Args[0]), flag.ExitOnError)
commands := make([]subcommands.Command, 0)
sb := NewStembuildHelp(subcommands.DefaultCommander, fs, &commands)
sb := commandparser.NewStembuildHelp(subcommands.DefaultCommander, fs, &commands)

sb.Explain(&buf)

Expand Down
8 changes: 4 additions & 4 deletions integration/construct/winrm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package construct_test
import (
"path/filepath"

. "github.com/cloudfoundry/stembuild/remotemanager"
"github.com/cloudfoundry/stembuild/remotemanager"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("WinRM Remote Manager", func() {

var rm RemoteManager
var rm remotemanager.RemoteManager

BeforeEach(func() {
clientFactory := NewWinRmClientFactory(conf.TargetIP, conf.VMUsername, conf.VMPassword)
rm = NewWinRM(conf.TargetIP, conf.VMUsername, conf.VMPassword, clientFactory)
clientFactory := remotemanager.NewWinRmClientFactory(conf.TargetIP, conf.VMUsername, conf.VMPassword)
rm = remotemanager.NewWinRM(conf.TargetIP, conf.VMUsername, conf.VMPassword, clientFactory)
Expect(rm).ToNot(BeNil())
})

Expand Down
32 changes: 16 additions & 16 deletions package_stemcell/config/output_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"path/filepath"

. "github.com/cloudfoundry/stembuild/package_stemcell/config"
"github.com/cloudfoundry/stembuild/package_stemcell/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -13,36 +13,36 @@ var _ = Describe("OutputConfig", func() {
Describe("os", func() {
Context("no os specified", func() {
It("should be invalid", func() {
valid := IsValidOS("")
valid := config.IsValidOS("")
Expect(valid).To(BeFalse())
})
})
Context("a supported os is specified", func() {
It("2016 should be valid", func() {
valid := IsValidOS("2016")
valid := config.IsValidOS("2016")
Expect(valid).To(BeTrue())
})
It("2012R2 should be valid", func() {
valid := IsValidOS("2012R2")
valid := config.IsValidOS("2012R2")
Expect(valid).To(BeTrue())
})
It("1803 should be valid", func() {
valid := IsValidOS("1803")
valid := config.IsValidOS("1803")
Expect(valid).To(BeTrue())
})
It("2019 should be valid", func() {
valid := IsValidOS("2019")
valid := config.IsValidOS("2019")
Expect(valid).To(BeTrue())
})

})
Context("something other than a supported os is specified", func() {
It("should be invalid", func() {
valid := IsValidOS("bad-thing")
valid := config.IsValidOS("bad-thing")
Expect(valid).To(BeFalse())
})
It("1709 should be invalid", func() {
valid := IsValidOS("1709")
valid := config.IsValidOS("1709")
Expect(valid).To(BeFalse())
})
})
Expand All @@ -51,22 +51,22 @@ var _ = Describe("OutputConfig", func() {
Describe("stemcell version", func() {
Context("no stemcell version specified", func() {
It("should be invalid", func() {
valid := IsValidStemcellVersion("")
valid := config.IsValidStemcellVersion("")
Expect(valid).To(BeFalse())
})
})
Context("stemcell version specified is valid pattern", func() {
It("should be valid", func() {
valids := []string{"4.4", "4.4-build.1", "4.4.4", "4.4.4-build.4"}
for _, version := range valids {
valid := IsValidStemcellVersion(version)
valid := config.IsValidStemcellVersion(version)
Expect(valid).To(BeTrue())
}
})
})
Context("stemcell version specified is invalid pattern", func() {
It("should be invalid", func() {
valid := IsValidStemcellVersion("4.4.4.4")
valid := config.IsValidStemcellVersion("4.4.4.4")
Expect(valid).To(BeFalse())
})
})
Expand All @@ -75,7 +75,7 @@ var _ = Describe("OutputConfig", func() {
Describe("validateOutputDir", func() {
Context("no dir given", func() {
It("should be an error", func() {
err := ValidateOrCreateOutputDir("")
err := config.ValidateOrCreateOutputDir("")
Expect(err).To(HaveOccurred())
})
})
Expand All @@ -84,7 +84,7 @@ var _ = Describe("OutputConfig", func() {
It("should create the directory and not fail", func() {
err := os.RemoveAll(filepath.Join(".", "tmp"))
Expect(err).ToNot(HaveOccurred())
err = ValidateOrCreateOutputDir(filepath.Join(".", "tmp"))
err = config.ValidateOrCreateOutputDir(filepath.Join(".", "tmp"))
Expect(err).ToNot(HaveOccurred())
_, err = os.Stat(filepath.Join(filepath.Join(".", "tmp")))
Expect(err).ToNot(HaveOccurred())
Expand All @@ -99,7 +99,7 @@ var _ = Describe("OutputConfig", func() {
It("should not fail", func() {
err := os.Mkdir(filepath.Join(".", "tmp"), 0700)
Expect(err).ToNot(HaveOccurred())
err = ValidateOrCreateOutputDir(filepath.Join(".", "tmp"))
err = config.ValidateOrCreateOutputDir(filepath.Join(".", "tmp"))
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
Expand All @@ -112,7 +112,7 @@ var _ = Describe("OutputConfig", func() {
It("should not fail", func() {
cwd, err := os.Getwd()
Expect(err).ToNot(HaveOccurred())
err = ValidateOrCreateOutputDir(cwd)
err = config.ValidateOrCreateOutputDir(cwd)
Expect(err).ToNot(HaveOccurred())
})
})
Expand All @@ -121,7 +121,7 @@ var _ = Describe("OutputConfig", func() {
It("should be an error", func() {
err := os.RemoveAll(filepath.Join(".", "tmp"))
Expect(err).ToNot(HaveOccurred())
err = ValidateOrCreateOutputDir(filepath.Join(".", "tmp", "subtmp"))
err = config.ValidateOrCreateOutputDir(filepath.Join(".", "tmp", "subtmp"))
Expect(err).To(HaveOccurred())
})
})
Expand Down
32 changes: 16 additions & 16 deletions package_stemcell/config/source_config_test.go
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
package config_test

import (
. "github.com/cloudfoundry/stembuild/package_stemcell/config"
"github.com/cloudfoundry/stembuild/package_stemcell/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("SourceConfig", func() {
Describe("GetSource", func() {
It("returns no error when VMDK configured correctly", func() {
config := SourceConfig{
srcConfig := config.SourceConfig{
Vmdk: "/some/path/to/a/file",
}
source, err := config.GetSource()
source, err := srcConfig.GetSource()
Expect(err).NotTo(HaveOccurred())
Expect(source).To(Equal(VMDK))
Expect(source).To(Equal(config.VMDK))
})

It("returns an error when no configuration provided", func() {
config := SourceConfig{}
source, err := config.GetSource()
srcConfig := config.SourceConfig{}
source, err := srcConfig.GetSource()
Expect(err).To(MatchError("no configuration was provided"))
Expect(source).To(Equal(NIL))
Expect(source).To(Equal(config.NIL))
})

It("return no error when vCenter configured correctly", func() {
config := SourceConfig{
srcConfig := config.SourceConfig{
VmInventoryPath: "/my-datacenter/vm/my-folder/my-vm",
Username: "user",
Password: "pass",
URL: "https://vcenter.test",
}
source, err := config.GetSource()
source, err := srcConfig.GetSource()
Expect(err).NotTo(HaveOccurred())
Expect(source).To(Equal(VCENTER))
Expect(source).To(Equal(config.VCENTER))

})

It("returns an error when both VMDK and Vcenter configured", func() {
config := SourceConfig{
srcConfig := config.SourceConfig{
Vmdk: "/some/path/to/a/file",
VmInventoryPath: "/my-datacenter/vm/my-folder/my-vm",
Username: "user",
Password: "pass",
URL: "https://vcenter.test",
}
source, err := config.GetSource()
source, err := srcConfig.GetSource()
Expect(err).To(MatchError("configuration provided for VMDK & vCenter sources"))
Expect(source).To(Equal(NIL))
Expect(source).To(Equal(config.NIL))

})

It("returns an error when Vcenter configurations only partially specified", func() {
config := SourceConfig{
srcConfig := config.SourceConfig{
VmInventoryPath: "/my-datacenter/vm/my-folder/my-vm",
Username: "user",
URL: "https://vcenter.test",
}
source, err := config.GetSource()
source, err := srcConfig.GetSource()
Expect(err).To(MatchError("missing vCenter configurations"))
Expect(source).To(Equal(NIL))
Expect(source).To(Equal(config.NIL))
})

})
Expand Down
Loading

0 comments on commit 3976898

Please sign in to comment.