-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch from Ginkgo to stdlib testing (#57)
* refactor: switch add_test to testing pkg * refactor: switch multiple test files to testing pkg * refactor: all of cmd to use testing library instead of ginkgo * refactor: move most of pkg/kubeconfig to testing pkg * refactor: convert most of kubeconfig to testing pkg * refactor: switch all of kubeconfig to testing pkg * refactor: cleanup remaining ginkgo items * chore: add tool-versions file for asdf * docs: update pull request template
- Loading branch information
1 parent
e1c0df2
commit 4621b5f
Showing
28 changed files
with
1,793 additions
and
1,429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,9 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
go mod vendor | ||
- name: Install Ginkgo | ||
run: | | ||
go install github.com/onsi/ginkgo/v2/ginkgo@latest | ||
- name: Run tests | ||
run: | | ||
ginkgo -r -cover -covermode count --randomize-all --randomize-suites -coverprofile coverage.out --output-dir . -nodes 2 | ||
go test -shuffle on -race -coverprofile coverage.out ./... | ||
- name: Convert Go coverage to LCOV | ||
uses: jandelgado/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,12 +52,9 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
go mod vendor | ||
- name: Install Ginkgo | ||
run: | | ||
go install github.com/onsi/ginkgo/v2/ginkgo | ||
- name: Run tests | ||
run: | | ||
ginkgo -r -cover -covermode count --randomize-all --randomize-suites -coverprofile coverage.out --output-dir . -nodes 2 | ||
go test -shuffle on -race -coverprofile coverage.out ./... | ||
- name: Convert Go coverage to LCOV | ||
uses: jandelgado/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pre-commit 3.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,132 @@ | ||
package build_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"io" | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"testing" | ||
|
||
"github.com/particledecay/kconf/build" | ||
. "github.com/particledecay/kconf/test" | ||
) | ||
|
||
var _ = Describe("Build/PrintVersion", func() { | ||
It("Should print nothing if a version is not set", func() { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
// all this function does is print to stdout | ||
build.Version = "" | ||
build.PrintVersion() | ||
|
||
// read captured stdout | ||
w.Close() | ||
out, _ := ioutil.ReadAll(r) | ||
|
||
// restore stdout | ||
os.Stdout = oldStdout | ||
|
||
Expect(out).To(BeEmpty()) | ||
}) | ||
|
||
It("Should print a version if it was set", func() { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
// all this function does is print to stdout | ||
build.Version = "1.2.3" | ||
build.PrintVersion() | ||
|
||
// read captured stdout | ||
w.Close() | ||
out, _ := ioutil.ReadAll(r) | ||
|
||
// restore stdout | ||
os.Stdout = oldStdout | ||
|
||
Expect(string(out)).To(Equal("v1.2.3\n")) | ||
}) | ||
}) | ||
|
||
var _ = Describe("Build/PrintLongVersion", func() { | ||
It("Should print nothing if a version is not set", func() { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
// all this function does is print to stdout | ||
build.Version = "" | ||
build.PrintLongVersion() | ||
|
||
// read captured stdout | ||
w.Close() | ||
out, _ := ioutil.ReadAll(r) | ||
|
||
// restore stdout | ||
os.Stdout = oldStdout | ||
|
||
Expect(out).To(BeEmpty()) | ||
}) | ||
|
||
It("Should print a version if it was set", func() { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
// all this function does is print to stdout | ||
build.Version = "1.2.3" | ||
build.Commit = "abcdef1234" | ||
build.Date = "20200101" | ||
build.PrintLongVersion() | ||
|
||
// read captured stdout | ||
w.Close() | ||
out, _ := ioutil.ReadAll(r) | ||
|
||
// restore stdout | ||
os.Stdout = oldStdout | ||
|
||
Expect(string(out)).To(ContainSubstring("Version:")) | ||
Expect(string(out)).To(ContainSubstring("v1.2.3")) | ||
Expect(string(out)).To(ContainSubstring("SHA:")) | ||
Expect(string(out)).To(ContainSubstring("abcdef1234")) | ||
Expect(string(out)).To(ContainSubstring("Built On:")) | ||
Expect(string(out)).To(ContainSubstring("20200101")) | ||
}) | ||
}) | ||
func TestPrintVersion(t *testing.T) { | ||
var tests = map[string]func(*testing.T){ | ||
"print nothing if version not set": func(t *testing.T) { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
defer func() { | ||
w.Close() | ||
os.Stdout = oldStdout | ||
|
||
// read captured stdout | ||
out, _ := io.ReadAll(r) | ||
|
||
if len(out) != 0 { | ||
t.Errorf("expected: empty, got: %s", string(out)) | ||
} | ||
}() | ||
|
||
// all this function does is print to stdout | ||
build.Version = "" | ||
build.PrintVersion() | ||
}, | ||
"print a version if set": func(t *testing.T) { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
defer func() { | ||
w.Close() | ||
os.Stdout = oldStdout | ||
|
||
// read captured stdout | ||
out, _ := io.ReadAll(r) | ||
|
||
if string(out) != "v1.2.3\n" { | ||
t.Errorf("expected: v1.2.3, got: %s", string(out)) | ||
} | ||
}() | ||
|
||
// all this function does is print to stdout | ||
build.Version = "1.2.3" | ||
build.PrintVersion() | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, test) | ||
} | ||
} | ||
|
||
func TestPrintLongVersion(t *testing.T) { | ||
var tests = map[string]func(*testing.T){ | ||
"print nothing if version not set": func(t *testing.T) { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
defer func() { | ||
w.Close() | ||
os.Stdout = oldStdout | ||
|
||
// read captured stdout | ||
out, _ := io.ReadAll(r) | ||
|
||
if len(out) != 0 { | ||
t.Errorf("expected: empty, got: %s", string(out)) | ||
} | ||
}() | ||
|
||
// all this function does is print to stdout | ||
build.Version = "" | ||
err := build.PrintLongVersion() | ||
if err != nil { | ||
t.Errorf("expected: nil, got: %v", err) | ||
} | ||
}, | ||
"print a version if set": func(t *testing.T) { | ||
// redirect stdout | ||
oldStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
defer func() { | ||
w.Close() | ||
os.Stdout = oldStdout | ||
|
||
// read captured stdout | ||
out, _ := io.ReadAll(r) | ||
|
||
// expected substrings | ||
expected := []string{ | ||
"Version", | ||
"v1.2.3", | ||
"SHA", | ||
"abcdef1234", | ||
"Built On", | ||
"20200101", | ||
} | ||
|
||
AssertSubstrings(t, out, expected) | ||
}() | ||
|
||
// all this function does is print to stdout | ||
build.Version = "1.2.3" | ||
build.Commit = "abcdef1234" | ||
build.Date = "20200101" | ||
err := build.PrintLongVersion() | ||
if err != nil { | ||
t.Errorf("expected: nil, got: %v", err) | ||
} | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, test) | ||
} | ||
} |
Oops, something went wrong.