Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 31, 2023
1 parent b6ead99 commit bbed976
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
14 changes: 8 additions & 6 deletions publisher/app/cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ func TestDeploy_Do(t *testing.T) {

require.NoError(t, d.Do(123))
require.Equal(t, 3, len(ex.RunCalls()))
assert.Equal(t, "git pull && git commit -am episode %d && git push", ex.RunCalls()[0].Cmd)
assert.Equal(t, []string{"123"}, ex.RunCalls()[0].Params)
assert.Equal(t, `ssh [email protected] "cd /srv/site.hugo && git pull && docker-compose run --rm hugo"`, ex.RunCalls()[1].Cmd)
assert.Equal(t, 0, len(ex.RunCalls()[1].Params))
assert.Equal(t, `ssh [email protected] "docker exec -i super-bot /srv/telegram-rt-bot --super=umputun --super=bobuk --super=ksenks --super=grayodesa --dbg --export-num=%d --export-path=/srv/html"`, ex.RunCalls()[2].Cmd)
assert.Equal(t, []string{"123"}, ex.RunCalls()[2].Params)
assert.Equal(t, "git pull && git commit -am \"episode 123\" && git push", ex.RunCalls()[0].Cmd)
assert.Equal(t, 0, len(ex.RunCalls()[0].Params))
assert.Equal(t, `ssh [email protected]`, ex.RunCalls()[1].Cmd)
assert.Equal(t, 1, len(ex.RunCalls()[1].Params))
assert.Equal(t, `cd /srv/site.hugo && git pull && docker-compose run --rm hugo`, ex.RunCalls()[1].Params[0])

assert.Equal(t, `ssh [email protected]`, ex.RunCalls()[2].Cmd)
assert.Equal(t, []string{"docker exec -i super-bot /srv/telegram-rt-bot --super=umputun --super=bobuk --super=ksenks --super=grayodesa --dbg --export-num=123 --export-path=/srv/html"}, ex.RunCalls()[2].Params)

}

Expand Down
15 changes: 11 additions & 4 deletions publisher/app/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ var artifactsFS embed.FS
// Upload handles podcast upload to all destinations. It uses spot to deploy and set mp3 tags before deploy
type Upload struct {
Executor
LocationMp3 string
LocationPost string
LocationMp3 string
LocationPosts string
Dry bool
}

// Do runs uploads for given episode
func (u *Upload) Do(episodeNum int) error {
log.Printf("[INFO] upload episode %d, mp3 location:%q, posts location:%q", episodeNum, u.LocationMp3, u.LocationPosts)
mp3file := fmt.Sprintf("%s/rt_podcast%d/rt_podcast%d.mp3", u.LocationMp3, episodeNum, episodeNum)
hugoPost := fmt.Sprintf("%s/podcast-%d.md", u.LocationPost, episodeNum)
log.Printf("[DEBUG] mp3 file %s", mp3file)
hugoPost := fmt.Sprintf("%s/podcast-%d.md", u.LocationPosts, episodeNum)
log.Printf("[DEBUG] hugo post file %s", hugoPost)
posstContent, err := os.ReadFile(hugoPost)
if err != nil {
return fmt.Errorf("can't read post file %s, %w", hugoPost, err)
Expand All @@ -35,6 +39,7 @@ func (u *Upload) Do(episodeNum int) error {
if err != nil {
return fmt.Errorf("can't parse chapters from post %s, %w", hugoPost, err)
}
log.Printf("[DEBUG] chapters %v", chapters)

err = u.setMp3Tags(episodeNum, chapters)
if err != nil {
Expand All @@ -57,7 +62,9 @@ type chapter struct {
func (u *Upload) setMp3Tags(episodeNum int, chapters []chapter) error {
mp3file := fmt.Sprintf("%s/rt_podcast%d/rt_podcast%d.mp3", u.LocationMp3, episodeNum, episodeNum)
log.Printf("[INFO] set mp3 tags for %s", mp3file)

if u.Dry {
return nil
}
tag, err := id3v2.Open(mp3file, id3v2.Options{Parse: true})
if err != nil {
return fmt.Errorf("can't open mp3 file %s, %w", mp3file, err)
Expand Down
6 changes: 3 additions & 3 deletions publisher/app/cmd/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func TestUpload_Do(t *testing.T) {
}

d := Upload{
Executor: ex,
LocationMp3: tempDir,
LocationPost: "testdata",
Executor: ex,
LocationMp3: tempDir,
LocationPosts: "testdata",
}

err = d.Do(123)
Expand Down
13 changes: 9 additions & 4 deletions publisher/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var opts struct {
} `command:"prep" description:"make new prep podcast post"`

UploadCmd struct {
Location string `long:"location" env:"LOCATION" default:"/Volumes/Podcasts/radio-t/" description:"podcast location"`
Location string `long:"location" env:"LOCATION" default:"/Volumes/Podcasts/radio-t/" description:"podcast location"`
HugoPosts string `long:"hugo-posts" env:"HUGO_POSTS" default:"/srv/hugo/content/posts" description:"hugo posts location"`
} `command:"upload" description:"upload podcast"`

DeployCmd struct {
Expand Down Expand Up @@ -122,10 +123,14 @@ func runPrep(episodeNum int) {

func runUpload(episodeNum int) {
upload := cmd.Upload{
Executor: &cmd.ShellExecutor{Dry: opts.Dry},
LocationMp3: opts.UploadCmd.Location,
Executor: &cmd.ShellExecutor{Dry: opts.Dry},
LocationMp3: opts.UploadCmd.Location,
LocationPosts: opts.UploadCmd.HugoPosts,
Dry: opts.Dry,
}
if err := upload.Do(episodeNum); err != nil {
log.Fatalf("[ERROR] failed to upload #%d, %v", episodeNum, err)
}
upload.Do(episodeNum)
log.Printf("[INFO] deployed #%d", episodeNum)
}

Expand Down

0 comments on commit bbed976

Please sign in to comment.