Skip to content

Commit

Permalink
chore: Adding new tests (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebeazer committed Jan 10, 2024
1 parent 68d0705 commit 710aeb7
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 51 deletions.
20 changes: 6 additions & 14 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ component_management:
branches:
- "!main"
individual_components:
- component_id: module_clean
name: clean
- component_id: module_fastlane
name: fastlane
paths:
- pkgs/clean/**
- component_id: module_jsonToXml
name: jsonToXml
- pkgs/fastlane/**
- component_id: module_flutter
name: flutter
paths:
- pkgs/jsonToXml/**
- component_id: module_parseLintReport
name: parseLintReport
paths:
- pkgs/parseLintReport/**
- component_id: module_projectVersion
name: projectVersion
paths:
- pkgs/projectVersion/**
- pkgs/flutter/**
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ module github.com/eddiebeazer/flutter-cli-tools

go 1.21

require github.com/urfave/cli/v2 v2.26.0
require (
github.com/google/go-github/v58 v58.0.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.26.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/go-github/v58 v58.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand Down
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHH
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v58 v58.0.0 h1:Una7GGERlF/37XfkPwpzYJe0Vp4dt2k1kCjlxwjIvzw=
github.com/google/go-github/v58 v58.0.0/go.mod h1:k4hxDKEfoWpSqFlc8LTpGd9fu2KrV1YAa6Hi6FmDNY4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
Expand All @@ -40,6 +54,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
Expand All @@ -59,6 +74,8 @@ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
repo := cCtx.String("repo")
version := cCtx.String("version")
release, err := fastlane.GetGithubRelease(owner, repo, version)
if err == nil {
if err != nil {
return err
}
log.Println(*release.TagName)
Expand Down Expand Up @@ -96,7 +96,7 @@ func main() {
repo := cCtx.String("repo")
draft := cCtx.Bool("draft")
release, err := fastlane.GetLatestGithubRelease(owner, repo, draft)
if err == nil {
if err != nil {
return err
}
log.Println(*release.TagName)
Expand Down
39 changes: 32 additions & 7 deletions pkgs/fastlane/fastlane_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
package fastlane

var (
defaultGameIniPath = "./DefaultGame.ini"
import (
"github.com/stretchr/testify/assert"
"testing"
)

//func TestSetVersion(t *testing.T) {
// expectedVersion := "2.1.1"
// err := ManuallySetVersion(expectedVersion, defaultGameIniPath)
// assert.Nil(t, err)
//}
func TestGetGithubReleases(t *testing.T) {
// Published release
release, err := GetLatestGithubRelease("eddiebeazer", "unreal-ci", false)
if err != nil {
return
}

assert.Equal(t, *release.TagName, "0.1.3")
}

func TestGetLatestDraftRelease(t *testing.T) {
// Draft Release
release, err := GetLatestGithubRelease("eddiebeazer", "unreal-ci", true)
if err != nil {
return
}

assert.Equal(t, *release.TagName, "0.1.4")
}

func TestGetGithubRelease(t *testing.T) {
// Draft Release
release, err := GetGithubRelease("eddiebeazer", "unreal-ci", "0.1.3")
if err != nil {
return
}

assert.NotNil(t, release)
}
18 changes: 11 additions & 7 deletions pkgs/flutter/app_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ package flutter
import (
"github.com/eddiebeazer/flutter-cli-tools/pkgs/fastlane"
"github.com/spf13/viper"
"log"
"os"
)

type Pubspec struct {
Version string `yaml:"version"`
}

func currentDir() (cwd string) {
func currentDir() (string, error) {
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
return "", err
}

return cwd
return cwd, err
}

func ParsePubspecFile() error {
dir, err := currentDir()
if err != nil {
return err
}

viper.SetConfigName("pubspec")
viper.AddConfigPath(currentDir())
viper.AddConfigPath(dir)

err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
err = viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
return err
}

Expand Down
77 changes: 60 additions & 17 deletions pkgs/flutter/app_version_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
package flutter

//func TestCleanDirectory(t *testing.T) {
// dirToTest := "Test"
// err := os.Mkdir(dirToTest, 777)
// assert.Nil(t, err)
//
// // Testing that we can successfully delete the "Test" directory
// err = Dist(dirToTest)
// assert.Nil(t, err)
//
// // Testing that we exit if the directory isn't provided
// err = Dist("")
// assert.NotNil(t, err)
//
// // Testing fake directory that does not exists
// err = Dist("aeed/asd//")
// assert.Nil(t, err)
//}
import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestGetAppVersion(t *testing.T) {
version, err := GetAppVersion()
if err != nil {
return
}
assert.Equal(t, version, "0.1.0+0")

// Manually setting app version
err = SetAppVersion("2.5.5", "23")
if err != nil {
return
}
version, err = GetAppVersion()
if err != nil {
return
}
assert.Equal(t, version, "2.5.5+23")

// Setting app version from Github
err = SetAppVersionFromLatestGithubRelease("eddiebeazer", "unreal-ci", false, "532")
if err != nil {
return
}
version, err = GetAppVersion()
if err != nil {
return
}
assert.Equal(t, version, "0.1.3+532")
}

func TestSetAppVersion(t *testing.T) {
// Manually setting app version
err := SetAppVersion("2.5.5", "23")
if err != nil {
return
}
version, err := GetAppVersion()
if err != nil {
return
}
assert.Equal(t, version, "2.5.5+23")
}

func TestSetAppVersionFromGitHub(t *testing.T) {
// Setting app version from Github
err := SetAppVersionFromLatestGithubRelease("eddiebeazer", "unreal-ci", false, "532")
if err != nil {
return
}
version, err := GetAppVersion()
if err != nil {
return
}
assert.Equal(t, version, "0.1.3+532")
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ flutter:
uses-material-design: true
name: form_app
publish_to: none
version: 0.1.4+233
version: 0.1.0+0

0 comments on commit 710aeb7

Please sign in to comment.