Skip to content

Commit

Permalink
test: add tests and display coverage info (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecobask authored Oct 11, 2023
1 parent 43a97cc commit b35c6ff
Show file tree
Hide file tree
Showing 28 changed files with 1,628 additions and 304 deletions.
13 changes: 13 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
precision: 2
round: nearest
range: "75...100"
status:
project:
default:
target: "75%"
threshold: "0%"
patch: false
changes: false
comment:
layout: "diff, files"
5 changes: 2 additions & 3 deletions .github/workflows/insights.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: insights
on:
workflow_dispatch:
env:
ARCHIVE_URL: ${{ secrets.ARCHIVE_URL }}
jobs:
unfollowers:
runs-on: ubuntu-latest
Expand All @@ -17,7 +16,7 @@ jobs:
- name: Add build directory to path
run: echo "${GITHUB_WORKSPACE}/build" >> $GITHUB_PATH
- name: Download Instagram information locally
run: instagram information download $ARCHIVE_URL
run: instagram information download ${{ secrets.ARCHIVE_URL }}
- name: Find out which Instagram users are not following back
run: instagram followdata unfollowers
- name: Cleanup local Instagram information
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: quality
on:
push:
branches:
Expand Down Expand Up @@ -41,3 +42,8 @@ jobs:
go-version: 1.21
- name: Run tests
run: make test
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: coverage.out
token: ${{ secrets.CODECOV_TOKEN }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
coverage.out
instagram_data.zip
instagram_data/
build/
instagram_data/
9 changes: 9 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
packages:
github.com/cecobask/instagram-insights/pkg/filesystem:
interfaces:
Fs:
config:
dir: "{{.InterfaceDir}}"
filename: "{{.PackageName}}_mock.go"
inpackage: true
outpkg: "{{.PackageName}}"
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ build:
fmt:
go fmt ./...

html-coverage:
go tool cover -html=coverage.out

lint:
golangci-lint run

lint-fix:
golangci-lint run --fix

test:
go test -race ./...
go test -coverpkg=./... -race -coverprofile=coverage.out -shuffle on ./...
cat coverage.out | grep -v 'pkg/filesystem/' > coverage.temp
mv coverage.temp coverage.out
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# instagram-insights
Discover various insights from your Instagram data.

[![quality](https://github.com/cecobask/instagram-insights/actions/workflows/quality.yaml/badge.svg)](https://github.com/cecobask/instagram-insights/actions/workflows/quality.yaml)
[![codecov](https://codecov.io/gh/cecobask/instagram-insights/graph/badge.svg)](https://codecov.io/gh/cecobask/instagram-insights)

## Use-cases
- Find out which instagram users are not following back
- Export followers and following lists
Expand Down
4 changes: 3 additions & 1 deletion cmd/followdata/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"github.com/spf13/cobra"
)

const CommandNameFollowdata = "followdata"

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "followdata",
Use: CommandNameFollowdata,
Short: "Instagram follow data operations",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
Expand Down
17 changes: 6 additions & 11 deletions cmd/followdata/unfollowers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ package followdata

import (
"github.com/cecobask/instagram-insights/pkg/instagram"
"github.com/cecobask/instagram-insights/pkg/instagram/followdata"
"github.com/spf13/cobra"
)

const CommandNameUnfollowers = "unfollowers"

func NewUnfollowersCommand() *cobra.Command {
return &cobra.Command{
Use: "unfollowers",
Use: CommandNameUnfollowers,
Short: "Find out which instagram users are not following back",
RunE: func(cmd *cobra.Command, args []string) error {
return run()
opts := instagram.NewOptions(instagram.OutputTable)
return followdata.NewHandler().Unfollowers(opts)
},
}
}

func run() error {
followData := instagram.NewFollowData()
if err := followData.ExtractAllData(); err != nil {
return err
}
followData.FindUnfollowers()
return nil
}
15 changes: 5 additions & 10 deletions cmd/information/cleanup.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package information

import (
"fmt"

"github.com/cecobask/instagram-insights/pkg/instagram"
"github.com/cecobask/instagram-insights/pkg/instagram/information"
"github.com/spf13/cobra"
)

const CommandNameCleanup = "cleanup"

func NewCleanupCommand() *cobra.Command {
return &cobra.Command{
Use: "cleanup",
Use: CommandNameCleanup,
Short: "Cleanup local instagram information",
RunE: func(cmd *cobra.Command, args []string) error {
err := instagram.CleanupInstagramInformation()
if err != nil {
return err
}
fmt.Println("cleaned up local instagram information")
return nil
return information.NewHandler().Cleanup()
},
}
}
13 changes: 5 additions & 8 deletions cmd/information/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package information
import (
"fmt"

"github.com/cecobask/instagram-insights/pkg/instagram"
"github.com/cecobask/instagram-insights/pkg/instagram/information"
"github.com/spf13/cobra"
)

const CommandNameDownload = "download"

func NewDownloadCommand() *cobra.Command {
return &cobra.Command{
Use: "download <url>",
Use: CommandNameDownload + " <url>",
Short: "Download instagram information locally",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
Expand All @@ -18,12 +20,7 @@ func NewDownloadCommand() *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
err := instagram.FetchInstagramInformation(args[0])
if err != nil {
return err
}
fmt.Println("downloaded instagram information locally")
return nil
return information.NewHandler().Download(args[0])
},
}
}
6 changes: 2 additions & 4 deletions cmd/information/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package information

import "github.com/spf13/cobra"

type Options struct {
ArchiveDownloadURL string
}
const CommandNameInformation = "information"

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "information",
Use: CommandNameInformation,
Short: "Instagram information operations",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
Expand Down
4 changes: 3 additions & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"github.com/spf13/cobra"
)

const CommandNameInstagram = "instagram"

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "instagram",
Use: CommandNameInstagram,
Short: "Instagram Insights CLI",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ module github.com/cecobask/instagram-insights
go 1.21

require (
github.com/jedib0t/go-pretty/v6 v6.4.7
github.com/jedib0t/go-pretty/v6 v6.4.8
github.com/spf13/cobra v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/sys v0.1.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.4.7 h1:lwiTJr1DEkAgzljsUsORmWsVn5MQjt1BPJdPCtJ6KXE=
github.com/jedib0t/go-pretty/v6 v6.4.7/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/jedib0t/go-pretty/v6 v6.4.8 h1:HiNzyMSEpsBaduKhmK+CwcpulEeBrTmxutz4oX/oWkg=
github.com/jedib0t/go-pretty/v6 v6.4.8/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
Expand All @@ -20,9 +20,14 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.4 h1:wZRexSlwd7ZXfKINDLsO4r7WBt3gTKONc6K/VesHvHM=
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
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=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func main() {
err := root.NewRootCommand().Execute()
if err != nil {
if err := root.NewRootCommand().Execute(); err != nil {
os.Exit(1)
}
}
96 changes: 0 additions & 96 deletions pkg/file/file.go

This file was deleted.

Loading

0 comments on commit b35c6ff

Please sign in to comment.