Skip to content

Commit

Permalink
work on coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bart6114 committed Dec 4, 2023
1 parent f4d5349 commit 7c262da
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 269 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,5 @@ cover.out
butt
*sheep
*.sqlite3
node_modules
node_modules
*.out
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"path"

cheek "github.com/datarootsio/cheek/pkg"
"github.com/spf13/cobra"
Expand All @@ -12,6 +13,7 @@ import (
var (
httpPort string
homeDir string
dbPath string
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -30,6 +32,7 @@ func Execute() {
func init() {
rootCmd.PersistentFlags().StringVar(&httpPort, "port", "8081", "port on which to open the http server for core to ui communication")
rootCmd.PersistentFlags().StringVar(&homeDir, "homedir", cheek.CheekPath(), fmt.Sprintf("directory in which to save cheek's core & job logs, defaults to '%s'", cheek.CheekPath()))
rootCmd.PersistentFlags().StringVar(&homeDir, "dbpath", path.Join(cheek.CheekPath(), "cheek.sqlite3"), fmt.Sprintf("path to sqlite3 db used for logging, defaults to '%s'", path.Join(cheek.CheekPath(), "cheek.sqlite3")))
cobra.OnInitialize(initConfig)
}

Expand Down Expand Up @@ -61,4 +64,8 @@ func initConfig() {
if err := viper.BindPFlag("homedir", rootCmd.PersistentFlags().Lookup("homedir")); err != nil {
fmt.Printf("error binding pflag %s", err)
}

if err := viper.BindPFlag("dbpath", rootCmd.PersistentFlags().Lookup("dbpath")); err != nil {
fmt.Printf("error binding pflag %s", err)
}
}
196 changes: 0 additions & 196 deletions coverage.out

This file was deleted.

69 changes: 0 additions & 69 deletions pkg/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,72 +223,3 @@ func postTrigger(s *Schedule) httprouter.Handle {
}
}
}

// endpoints needed
// /jobs
// /jobs/{jobid}
// /jobs/{jobid}/logs/{logid}

// func ui(s *Schedule) func(w http.ResponseWriter, r *http.Request) {

// return func(w http.ResponseWriter, r *http.Request) {

// // get jobid from url
// var jobId string
// var job *JobSpec
// var ok bool
// job = &JobSpec{}

// if strings.HasPrefix(r.URL.Path, "/job/") {
// jobId = strings.TrimPrefix(r.URL.Path, "/job/")
// job, ok = s.Jobs[jobId]
// if !ok {
// http.Error(w, fmt.Errorf("job %s not found", jobId).Error(), http.StatusNotFound)
// return
// } else {
// job.loadRunsFromDb(50, false)
// }
// }

// // get job ids
// jobNames := make([]string, 0)
// for k := range s.Jobs {
// jobNames = append(jobNames, k)
// }
// sort.Strings(jobNames)

// // add custom functions to template
// funcMap := template.FuncMap{
// "roundToSeconds": func(d time.Duration) int {
// return int(d.Seconds())
// },
// }

// // parse template files
// tmpl, err := template.New("index.html").Funcs(funcMap).ParseFS(fsys(), "*.html")
// if err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
// return
// }

// data := struct {
// SelectedJobName string
// JobNames []string
// JobSpecs map[string]*JobSpec
// SelectedJobSpec JobSpec
// }{SelectedJobName: jobId, JobNames: jobNames, SelectedJobSpec: *job}

// if jobId == "" {
// for _, j := range s.Jobs {
// j.loadRunsFromDb(5, false)
// }
// data.JobSpecs = s.Jobs
// }

// err = tmpl.Execute(w, data)
// if err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
// return
// }
// }
// }
46 changes: 46 additions & 0 deletions pkg/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,52 @@ func TestMux(t *testing.T) {
wantCode int
wantBody string
}{
{
schedule: &s2,
name: "/jobs/bertha/runs/1 must return xxx",
args: func(*testing.T) args {
req, err := http.NewRequest("GET", "/api/jobs/bertha/runs/2", nil)
if err != nil {
t.Fatalf("fail to create request: %s", err.Error())
}
return args{
req: req,
}
},
wantCode: http.StatusNotFound,
wantBody: "error: can't find job",
},
{
schedule: &s2,
name: "/jobs/bertha must return 200",
args: func(*testing.T) args {
req, err := http.NewRequest("GET", "/api/jobs/bertha", nil)
if err != nil {
t.Fatalf("fail to create request: %s", err.Error())
}
return args{
req: req,
}
},
wantCode: http.StatusOK,
wantBody: "MooIAmACow",
},
{
schedule: &s2,
name: "/jobs/bertha/1 must return 404",
args: func(*testing.T) args {
req, err := http.NewRequest("GET", "/api/jobs/bertha/1", nil)
if err != nil {
t.Fatalf("fail to create request: %s", err.Error())
}
return args{
req: req,
}
},
wantCode: http.StatusNotFound,
wantBody: "not found",
},

{
schedule: &s1,
name: "/healthz must return 200",
Expand Down
3 changes: 1 addition & 2 deletions pkg/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/signal"
"path"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -150,7 +149,7 @@ func (s *Schedule) now() time.Time {
}

func loadSchedule(log zerolog.Logger, cfg Config, fn string) (Schedule, error) {
db, err := OpenDB(path.Join(CheekPath(), cfg.DBPath))
db, err := OpenDB(cfg.DBPath)
if err != nil {
return Schedule{}, fmt.Errorf("open db: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
LogLevel string `yaml:"logLevel"`
HomeDir string `yaml:"homedir"`
Port string `yaml:"port"`
DBPath string `yaml:"dbname"`
DBPath string `yaml:"dbpath"`
}

func NewConfig() Config {
Expand Down

0 comments on commit 7c262da

Please sign in to comment.