Skip to content

Commit

Permalink
moved test data cleanup to script
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhatsharma committed May 8, 2022
1 parent 5a24712 commit 2139f88
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
16 changes: 14 additions & 2 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@
export ZINC_FIRST_ADMIN_USER=admin
export ZINC_FIRST_ADMIN_PASSWORD=Complexpass#123

go test -v ./... -race -covermode=atomic -coverprofile=coverage.out
go test ./... -race -covermode=atomic -coverprofile=coverage.out

rm -rf ./test/data
rm -rf ./pkg/handlers/data
rm -rf ./pkg/core/data
rm -rf ./pkg/auth/data

# make sure to set CODECOV_TOKEN env variable before doing this
# codecov -f coverage.out
# or
# bash <(curl -s https://codecov.io/bash)


# Example setup https://github.com/lluuiissoo/go-testcoverage/blob/main/.github/workflows/ci.yml

# enable threshold
COVERAGE_THRESHOLD=20

totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]'`

# clean up
rm -rf ./test/data
rm -rf ./pkg/handlers/data
rm -rf ./pkg/core/data
rm -rf ./pkg/auth/data
rm coverage.out
# clean up finished

echo "Total Coverage is $totalCoverage %"

diff=$(echo "$totalCoverage < $COVERAGE_THRESHOLD" | bc)
Expand Down
6 changes: 3 additions & 3 deletions pkg/auth/createuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

func TestCreateUser(t *testing.T) {
// os.Setenv("ZINC_FIRST_ADMIN_USER", "admin")
// os.Setenv("ZINC_FIRST_ADMIN_PASSWORD", "Complexpass#123")
os.Setenv("ZINC_FIRST_ADMIN_USER", "admin")
os.Setenv("ZINC_FIRST_ADMIN_PASSWORD", "Complexpass#123")
type args struct {
userID string
name string
Expand Down Expand Up @@ -67,5 +67,5 @@ func TestCreateUser(t *testing.T) {
})
}

os.RemoveAll("data")
// os.RemoveAll("data")
}
2 changes: 1 addition & 1 deletion pkg/auth/getuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestGetUser(t *testing.T) {
assert.Equal(t, got.Role, tt.want.Role)
assert.Equal(t, got1, tt.want1)

os.RemoveAll("data")
// os.RemoveAll("data")
})
}
}
10 changes: 4 additions & 6 deletions pkg/core/newindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package core

import (
"fmt"
"math/rand"
"os"
"strconv"
"testing"
"time"
Expand All @@ -44,8 +42,8 @@ func TestNewIndex(t *testing.T) {
})

// Cleanup data folder
err := os.RemoveAll("data")
if err != nil {
fmt.Println(err)
}
// err := os.RemoveAll("data")
// if err != nil {
// fmt.Println(err)
// }
}
3 changes: 1 addition & 2 deletions pkg/core/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package core

import (
"math/rand"
"os"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -206,5 +205,5 @@ func TestIndex_Search(t *testing.T) {
})
}

os.RemoveAll("data")
// os.RemoveAll("data")
}
3 changes: 1 addition & 2 deletions pkg/core/updatedocument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package core

import (
"math/rand"
"os"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -89,5 +88,5 @@ func TestIndex_UpdateDocument(t *testing.T) {
})
}

os.RemoveAll("data") // cleanup data folder
// os.RemoveAll("data") // cleanup data folder
}

0 comments on commit 2139f88

Please sign in to comment.