-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Improvements Initial
- Loading branch information
Adrian Gheorghe
committed
Jul 13, 2019
1 parent
b47c369
commit 6840246
Showing
22 changed files
with
1,106 additions
and
570 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
version: 2 | ||
|
||
jobs: | ||
test: | ||
docker: | ||
- image: circleci/golang:1.11 | ||
steps: | ||
- checkout | ||
- run: | ||
command: | | ||
go test -v ./... > /dev/null 2>&1 | ||
echo "Temp remove tests" | ||
build: | ||
docker: | ||
- image: circleci/golang:1.11 | ||
steps: | ||
- checkout | ||
- run: | ||
command: | | ||
mkdir -p ./artefacts | ||
cp VERSION ./artefacts/VERSION | ||
CGO_ENABLED=0 GOOS=linux go build -o ./artefacts/mediafaker-linux | ||
CGO_ENABLED=0 GOOS=darwin go build -o ./artefacts/mediafaker-darwin | ||
CGO_ENABLED=0 GOOS=windows go build -o ./artefacts/mediafaker-windows | ||
CGO_ENABLED=0 go build -o ./artefacts/mediafaker | ||
ls -al ./artefacts | ||
- persist_to_workspace: | ||
root: artefacts | ||
paths: | ||
- mediafaker-linux | ||
- mediafaker-darwin | ||
- mediafaker-windows | ||
- mediafaker | ||
- VERSION | ||
release: | ||
docker: | ||
# specify the version | ||
- image: cibuilds/github:0.10 | ||
steps: | ||
- attach_workspace: | ||
# Must be absolute path or relative path from working_directory | ||
at: ./artefacts | ||
- run: | ||
command: | | ||
ls -al ./artefacts | ||
VERSION=$(cat ./artefacts/VERSION) | ||
echo $VERSION | ||
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artefacts/ | ||
workflows: | ||
version: 2 | ||
test_and_build_and_release: | ||
jobs: | ||
- test | ||
- build: | ||
requires: | ||
- test | ||
filters: | ||
branches: | ||
only: master | ||
- release: | ||
requires: | ||
- build | ||
filters: | ||
branches: | ||
only: master | ||
|
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,4 +1,15 @@ | ||
base: | ||
go run $$(ls -1 *.go | grep -v _test.go) | ||
local: | ||
go run $$(ls -1 *.go | grep -v _test.go) local --source $(SOURCEPATH) --destination $(DESTPATH) --extcopy=".htaccess" --extcopy=".gitignore" | ||
tree-url: | ||
go run $$(ls -1 *.go | grep -v _test.go) url --extcopy=".htaccess" --extcopy=".gitignore" --destination "$(DESTPATH)" --source "$(URL)" | ||
go run $$(ls -1 *.go | grep -v _test.go) local --source $(SOURCEPATH) --destination $(DESTPATH) --extcopy=".htaccess" --extcopy=".gitignore" --jsonlog=$(JSONLOG) | ||
url: | ||
go run $$(ls -1 *.go | grep -v _test.go) url --extcopy=".htaccess" --extcopy=".gitignore" --destination "$(DESTPATH)" --source "$(URL)" --jsonlog=$(JSONLOG) | ||
|
||
ssh: | ||
go run $$(ls -1 *.go | grep -v _test.go) ssh --extcopy=".htaccess" --extcopy=".gitignore" --destination $(DESTPATH) --source "$(SOURCE)" --ssh-host "$(SSHHOST)" --ssh-user "$(SSHUSER)" --ssh-key "$(SSHKEY)" --jsonlog=$(JSONLOG) | ||
|
||
ver: | ||
go run $$(ls -1 *.go | grep -v _test.go) --version | ||
|
||
test: | ||
go test -v ./... |
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,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/adrian-gheorghe/mediafaker/fakers" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// SourcePath represents the local directory path that should be faked | ||
var SourcePath string | ||
|
||
func init() { | ||
RootCmd.AddCommand(Local) | ||
Local.Flags().StringVarP(&SourcePath, "source", "s", "", "Local Source Directory path which should be faked") | ||
} | ||
|
||
// Local represents the tree tree command | ||
var Local = &cobra.Command{ | ||
Use: "local", | ||
Short: "runs mediafaker on a local directory", | ||
Long: `This subcommand runs mediafaker on a local source directory and stores the files in a destination directory of your choice.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if SourcePath == "" { | ||
log.Fatal("Source directory has not been provided") | ||
return | ||
} | ||
|
||
if DestinationPath == "" { | ||
log.Fatal("Destination directory has not been provided") | ||
return | ||
} | ||
|
||
mediaFake := fakers.MediaFake{ | ||
SourcePath: SourcePath, | ||
MoniTreePath: "", | ||
DestinationPath: DestinationPath, | ||
ExtensionsToCopyAutomatically: ExtensionsToCopyAutomatically, | ||
MaximumSizeForCopy: MaximumSizeForCopy, | ||
TotalFaked: 0, | ||
TotalMissed: 0, | ||
TotalCopied: 0, | ||
TotalSourceSize: 0, | ||
TotalDestinationSize: 0, | ||
} | ||
error := mediaFake.Fake() | ||
if error != nil { | ||
log.Error(error) | ||
} | ||
|
||
log.Info("Media directory has been faked:", SourcePath) | ||
mediaFake.CalculateTotalDestinationSize() | ||
mediaFake.PrintInfo() | ||
}, | ||
} |
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,24 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"github.com/adrian-gheorghe/mediafaker/cmd" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestLocalBadParameters(t *testing.T) { | ||
defer func() { log.StandardLogger().ExitFunc = nil }() | ||
var fatal bool | ||
log.StandardLogger().ExitFunc = func(int) { fatal = true } | ||
|
||
fatal = false | ||
cmd.RootCmd.SetArgs([]string{"local"}) | ||
cmd.RootCmd.Execute() | ||
assert.Equal(t, true, fatal) | ||
|
||
fatal = false | ||
cmd.RootCmd.SetArgs([]string{"local", "--source", "--destination"}) | ||
cmd.RootCmd.Execute() | ||
assert.Equal(t, true, fatal) | ||
} |
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,22 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/adrian-gheorghe/mediafaker/cmd" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
log.SetOutput(ioutil.Discard) | ||
m.Run() | ||
} | ||
|
||
func TestVersionWorks(t *testing.T) { | ||
cmd.RootCmd.SetArgs([]string{"--version"}) | ||
assert.NotPanics(t, func() { | ||
assert.NoError(t, cmd.RootCmd.Execute()) | ||
}) | ||
} |
Oops, something went wrong.