Skip to content

Commit

Permalink
Changed test package names
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkjp committed Feb 12, 2019
1 parent 60a7d83 commit 6bc9ec7
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 51 deletions.
5 changes: 3 additions & 2 deletions al2/commands_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package al2
package al2_test

import (
"flag"
"github.com/ToQoz/gopwt"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2"
"github.com/announce/altogether/al2/helper"
"os"
"testing"
Expand All @@ -17,5 +18,5 @@ func TestMain(m *testing.M) {
}

func TestCommands(t *testing.T) {
assert.OK(t, Commands != nil)
assert.OK(t, al2.Commands != nil)
}
7 changes: 4 additions & 3 deletions al2/service_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package al2
package al2_test

import (
"bytes"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2"
"github.com/announce/altogether/al2/domain"
"github.com/announce/altogether/al2/helper"
"github.com/announce/altogether/al2/web"
Expand All @@ -13,10 +14,10 @@ func TestHandler_Perform(t *testing.T) {
defer helper.MustRemoveTmpDir()
out := bytes.Buffer{}
errOut := out
h := &Handler{
h := &al2.Handler{
AlfredPath: helper.EnsureDataPath(domain.Alfred, web.Config),
AlbertPath: helper.EnsureDataPath(domain.Albert, web.Config),
Mode: &Mode{
Mode: &al2.Mode{
DryRun: true,
Verbose: false,
},
Expand Down
15 changes: 8 additions & 7 deletions al2/web/albert_sites_test.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
package web
package web_test

import (
"bytes"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/web"
"github.com/google/uuid"
"strings"
"testing"
)

func newAlbertConfigDict() ConfigDict {
c1 := &SiteConfig{
func newAlbertConfigDict() web.ConfigDict {
c1 := &web.SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Trigger: "foo",
Name: "Sample description",
Url: "https://foo.example.com/{query}/",
}
c2 := &SiteConfig{
c2 := &web.SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Trigger: "bar",
Name: "Sample description",
Url: "https://bar.example.com/{query}/",
}
dict := make(ConfigDict)
dict := make(web.ConfigDict)
dict[c1.Id()] = c1
dict[c2.Id()] = c2
return dict
}

func TestAlbertSites_Encode(t *testing.T) {
dict := newAlbertConfigDict()
sites := AlbertSites{}
sites := web.AlbertSites{}
json, err := sites.Encode(dict)
assert.OK(t, json != nil)
assert.OK(t, len(json) > 0)
Expand All @@ -42,7 +43,7 @@ func TestAlbertSites_Encode(t *testing.T) {

func TestAlbertSites_Decode(t *testing.T) {
dict := newAlbertConfigDict()
sites := AlbertSites{}
sites := web.AlbertSites{}
json, _ := sites.Encode(dict)
data := bytes.NewReader(json)
err := sites.Decode(data)
Expand Down
15 changes: 8 additions & 7 deletions al2/web/alfred_sites_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
package web
package web_test

import (
"bytes"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/web"
"github.com/google/uuid"
"strings"
"testing"
)

func newAlfredConfigDict() ConfigDict {
c1 := &SiteConfig{
func newAlfredConfigDict() web.ConfigDict {
c1 := &web.SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Trigger: "foo ",
Name: "Sample description",
Url: "https://foo.example.com/%s/",
}
c2 := &SiteConfig{
c2 := &web.SiteConfig{
Trigger: "bar ",
Name: "Sample description",
Url: "https://bar.example.com/%s/",
}
dict := make(ConfigDict)
dict := make(web.ConfigDict)
dict[c1.Id()] = c1
dict[c2.Id()] = c2
return dict
}

func TestAlfredSites_Encode(t *testing.T) {
dict := newAlfredConfigDict()
sites := &AlfredSites{}
sites := &web.AlfredSites{}
json, err := sites.Encode(dict)
assert.OK(t, json != nil)
assert.OK(t, len(json) > 0)
Expand All @@ -39,7 +40,7 @@ func TestAlfredSites_Encode(t *testing.T) {

func TestAlfredSites_Decode(t *testing.T) {
dict := newAlfredConfigDict()
sites := &AlfredSites{}
sites := &web.AlfredSites{}
plist, _ := sites.Encode(dict)
data := bytes.NewReader(plist)
err := sites.Decode(data)
Expand Down
9 changes: 5 additions & 4 deletions al2/web/config_dict_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package web
package web_test

import (
"crypto/sha1"
"fmt"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/web"
"strings"
"testing"
)

func TestConfigDict_String(t *testing.T) {
dict := make(ConfigDict)
dict := make(web.ConfigDict)
assert.OK(t, len(fmt.Sprintf("%s", dict)) == 0)
dict[sha1.Sum([]byte("a"))] = &SiteConfig{}
dict[sha1.Sum([]byte("a"))] = &web.SiteConfig{}
assert.OK(t, strings.Count(dict.String(), "\n") == 0)
dict[sha1.Sum([]byte("b"))] = &SiteConfig{}
dict[sha1.Sum([]byte("b"))] = &web.SiteConfig{}
assert.OK(t, strings.Count(dict.String(), "\n") == 1)
}
17 changes: 9 additions & 8 deletions al2/web/launcher_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package web
package web_test

import (
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/domain"
"github.com/announce/altogether/al2/helper"
"github.com/announce/altogether/al2/web"
"testing"
)

func newLauncher(p domain.Type) *Launcher {
launcher := &Launcher{
func newLauncher(p domain.Type) *web.Launcher {
launcher := &web.Launcher{
Type: p,
BasePath: helper.EnsureDataPath(p, Config),
BasePath: helper.EnsureDataPath(p, web.Config),
}
launcher.Init()
return launcher
Expand Down Expand Up @@ -53,14 +54,14 @@ func TestLauncher_Parse(t *testing.T) {
func TestLauncher_Populate(t *testing.T) {
defer helper.MustRemoveTmpDir()
t.Run("it works with Alfred", func(t *testing.T) {
dict := make(ConfigDict)
dict := make(web.ConfigDict)
launcher := newLauncher(domain.Alfred)
_ = launcher.Parse()
launcher.Populate(dict)
assert.OK(t, len(dict) > 0)
})
t.Run("it works with Albert", func(t *testing.T) {
dict := make(ConfigDict)
dict := make(web.ConfigDict)
launcher := newLauncher(domain.Albert)
_ = launcher.Parse()
launcher.Populate(dict)
Expand All @@ -71,7 +72,7 @@ func TestLauncher_Populate(t *testing.T) {
func TestLauncher_Save(t *testing.T) {
defer helper.MustRemoveTmpDir()
t.Run("it works with Alfred", func(t *testing.T) {
dict := make(ConfigDict)
dict := make(web.ConfigDict)
launcher := newLauncher(domain.Alfred)
_ = launcher.Load()
_ = launcher.Parse()
Expand All @@ -80,7 +81,7 @@ func TestLauncher_Save(t *testing.T) {
assert.OK(t, err == nil)
})
t.Run("it works with Albert", func(t *testing.T) {
dict := make(ConfigDict)
dict := make(web.ConfigDict)
launcher := newLauncher(domain.Albert)
_ = launcher.Load()
_ = launcher.Parse()
Expand Down
19 changes: 10 additions & 9 deletions al2/web/pair_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package web
package web_test

import (
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/domain"
"github.com/announce/altogether/al2/helper"
"github.com/announce/altogether/al2/web"
"testing"
"time"
)

func newPair() (*Pair, error) {
pair := &Pair{
&Launcher{
func newPair() (*web.Pair, error) {
pair := &web.Pair{
&web.Launcher{
Type: domain.Alfred,
BasePath: helper.EnsureDataPath(domain.Alfred, Config),
BasePath: helper.EnsureDataPath(domain.Alfred, web.Config),
},
&Launcher{
&web.Launcher{
Type: domain.Albert,
BasePath: helper.EnsureDataPath(domain.Albert, Config),
BasePath: helper.EnsureDataPath(domain.Albert, web.Config),
}}
return pair, pair.Load()
}
Expand All @@ -35,7 +36,7 @@ func TestPair_Merge(t *testing.T) {
helper.MustTouchFile(path0, 0)
helper.MustTouchFile(path1, 1*time.Nanosecond)
_ = pair.Load()
pair.Merge(make(ConfigDict))
pair.Merge(make(web.ConfigDict))
assert.OK(t, pair[0].ConfigPath == path0)
assert.OK(t, pair[1].ConfigPath == path1)
})
Expand All @@ -45,7 +46,7 @@ func TestPair_Merge(t *testing.T) {
helper.MustTouchFile(path1, 0)
helper.MustTouchFile(path0, 1*time.Nanosecond)
_ = pair.Load()
pair.Merge(make(ConfigDict))
pair.Merge(make(web.ConfigDict))
//log.Printf("(p1, p1)=(%v,%v)(%v, %v)",
// pair[0].Type, pair[1].Type, pair[0].Mtime(), pair[1].Mtime())
assert.OK(t, pair[1].ConfigPath == path0)
Expand Down
11 changes: 6 additions & 5 deletions al2/web/site_config_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package web
package web_test

import (
"encoding/hex"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/domain"
"github.com/announce/altogether/al2/web"
"github.com/google/uuid"
"strings"
"testing"
)

func newSiteConfig(p domain.Type) *SiteConfig {
config := &SiteConfig{}
func newSiteConfig(p domain.Type) *web.SiteConfig {
config := &web.SiteConfig{}
switch p {
case domain.Alfred:
{
config = &SiteConfig{
config = &web.SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Expand All @@ -25,7 +26,7 @@ func newSiteConfig(p domain.Type) *SiteConfig {
}
case domain.Albert:
{
config = &SiteConfig{
config = &web.SiteConfig{
Trigger: "jj ",
Name: "Sample description",
Url: "https://example.com/%s/",
Expand Down
13 changes: 7 additions & 6 deletions al2/web/web_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package web
package web_test

import (
"bytes"
"flag"
"github.com/ToQoz/gopwt"
"github.com/ToQoz/gopwt/assert"
"github.com/announce/altogether/al2/helper"
"github.com/announce/altogether/al2/web"
"os"
"strings"
"testing"
Expand All @@ -23,19 +24,19 @@ func TestWeb_Sync(t *testing.T) {
out := bytes.Buffer{}
errOut := out
pair, _ := newPair()
web := Web{
w := web.Web{
Launchers: pair,
Out: &out,
ErrOut: &errOut,
}
t.Run("it works with no dry-run option", func(t *testing.T) {
err := web.Sync(Option{DtyRun: false, Verbose: false})
err := w.Sync(web.Option{DtyRun: false, Verbose: false})
assert.OK(t, err == nil)
assert.OK(t, web.ConfigDict != nil)
assert.OK(t, w.ConfigDict != nil)
})
t.Run("it works with dry-run option", func(t *testing.T) {
err := web.Sync(Option{DtyRun: true, Verbose: true})
err := w.Sync(web.Option{DtyRun: true, Verbose: true})
assert.OK(t, err == nil)
assert.OK(t, strings.Count(out.String(), "\n") == len(web.ConfigDict))
assert.OK(t, strings.Count(out.String(), "\n") == len(w.ConfigDict))
})
}

0 comments on commit 6bc9ec7

Please sign in to comment.