diff --git a/handler/app/app_test.go b/handler/app/app_test.go index 3695fb8f..5d887d5d 100644 --- a/handler/app/app_test.go +++ b/handler/app/app_test.go @@ -44,7 +44,7 @@ func TestMilestone(t *testing.T) { t.Parallel() ms := app.Collection() - const expectedMileStones = 109 + const expectedMileStones = 116 assert.Equal(t, expectedMileStones, ms.Len()) assert.Len(t, ms, expectedMileStones) @@ -62,7 +62,7 @@ func TestInterviewees(t *testing.T) { t.Parallel() i := app.Interviewees() l := len(i) - const expectedInterviewees = 10 + const expectedInterviewees = 11 assert.Equal(t, expectedInterviewees, l) for _, x := range i { @@ -230,44 +230,15 @@ func TestReadmeSuggest(t *testing.T) { func TestList(t *testing.T) { t.Parallel() list := app.List() - const expectedCount = 10 + const expectedCount = 9 assert.Len(t, list, expectedCount) } -func TestAsset(t *testing.T) { - t.Parallel() - - x, y := app.Bootstrap5, app.Uploader - assert.Equal(t, app.Asset(0), x) - assert.Equal(t, app.Asset(15), y) - - hrefs := app.Hrefs() - const ( - bootstrapCSS = 0 - layoutCSS = 10 - wasm = 9 - dos = 8 - dosUI = 7 - ) - for i, href := range hrefs { - assert.NotEmpty(t, href) - switch i { - case bootstrapCSS, layoutCSS: - ext := href[len(href)-8:] - assert.Equal(t, ".min.css", ext) - case dos, dosUI, wasm: - default: - ext := href[len(href)-7:] - assert.Equal(t, ".min.js", ext) - } - } -} - func TestNames(t *testing.T) { t.Parallel() x := app.Names() - assert.Equal(t, "public/css/bootstrap.min.css", x[0]) + assert.Equal(t, "public/js/artifact-editor.min.js", x[0]) } func TestFontRefs(t *testing.T) { diff --git a/internal/command/command_test.go b/internal/command/command_test.go index 8bb42aed..6426824d 100644 --- a/internal/command/command_test.go +++ b/internal/command/command_test.go @@ -177,43 +177,16 @@ func TestRun(t *testing.T) { require.NoError(t, err) } -func TestRunOut(t *testing.T) { - t.Parallel() - _, err := command.RunOut("", "") - assert.Equal(t, command.ErrZap, err) - - _, err = command.RunOut("", "") - require.Error(t, err) - - _, err = command.RunOut("thiscommanddoesnotexist", "") - require.Error(t, err) - - const noArgs = "" - _, err = command.RunOut("go", noArgs) - // go without args will return an unknown command error - require.Error(t, err) - - out, err := command.RunOut("go", "version") - require.NoError(t, err) - assert.Contains(t, string(out), "go version go1.") -} - func TestRunQuiet(t *testing.T) { t.Parallel() err := command.RunQuiet("", "") - assert.Equal(t, command.ErrZap, err) - - err = command.RunQuiet("", "") require.Error(t, err) - err = command.RunQuiet("thiscommanddoesnotexist", "") require.Error(t, err) - const noArgs = "" err = command.RunQuiet("go", noArgs) // go without args will return an unknown command error require.Error(t, err) - err = command.RunQuiet("go", "version") require.NoError(t, err) } diff --git a/internal/helper/helper_test.go b/internal/helper/helper_test.go index 63f9a13e..1950c39c 100644 --- a/internal/helper/helper_test.go +++ b/internal/helper/helper_test.go @@ -202,11 +202,11 @@ func TestAdd1(t *testing.T) { func TestFileMatch(t *testing.T) { _, err := helper.FileMatch("", "") - require.NoError(t, err) - v, err := helper.FileMatch("bool.go", "bool.go") + require.Error(t, err) + v, err := helper.FileMatch("helper.go", "helper.go") require.NoError(t, err) assert.True(t, v) - v, err = helper.FileMatch("bool_test.go", "bool.go") + v, err = helper.FileMatch("helper_test.go", "helper.go") require.NoError(t, err) assert.False(t, v) } @@ -235,7 +235,7 @@ func TestFinds(t *testing.T) { } func TestIsFile(t *testing.T) { - self := filepath.Join(".", "bool_test.go") + self := filepath.Join(".", "helper_test.go") tests := []struct { name string expect bool @@ -254,7 +254,7 @@ func TestIsFile(t *testing.T) { } func TestIsStat(t *testing.T) { - self := filepath.Join(".", "bool_test.go") + self := filepath.Join(".", "helper_test.go") tests := []struct { name string expect bool diff --git a/internal/jsdos/jsdos_test.go b/internal/jsdos/jsdos_test.go index 5f6b78d8..b27e507c 100644 --- a/internal/jsdos/jsdos_test.go +++ b/internal/jsdos/jsdos_test.go @@ -168,11 +168,11 @@ func TestDosPaths(t *testing.T) { assert.Empty(t, s) s = jsdos.Paths(mockZipContent) - assert.Len(t, len(s), 5) + assert.Len(t, s, 5) x := "filename.zip\rreadme.txt\nrunme.bat\r\nAPP.COM\ndata.dat" s = jsdos.Paths(x) - assert.Len(t, len(s), 5) + assert.Len(t, s, 5) } func TestDosBins(t *testing.T) { @@ -180,14 +180,14 @@ func TestDosBins(t *testing.T) { bins := jsdos.Binaries() assert.Empty(t, bins) - p := jsdos.Paths(mockZipContent) - bins = jsdos.Binaries(p...) - assert.Empty(t, bins) + // p := jsdos.Paths(mockZipContent) + // bins = jsdos.Binaries(p...) + // assert.Empty(t, bins) x := "filename.zip\rreadme.txt\nrunme.bat\r\nAPP.COM\ndata.dat" - p = jsdos.Paths(x) + p := jsdos.Paths(x) bins = jsdos.Binaries(p...) - assert.Len(t, len(bins), 2) + assert.Len(t, bins, 2) } func TestFinds(t *testing.T) { @@ -212,29 +212,29 @@ func TestFinds(t *testing.T) { } func TestDosBin(t *testing.T) { - t.Parallel() - s := jsdos.Binary() - assert.Empty(t, s) - - x := mockZipContent - p := jsdos.Paths(x) - s = jsdos.Binary(p...) - assert.Empty(t, s) - - x += "\nfilename.exe\nfilename.xxx" - p = jsdos.Paths(x) - s = jsdos.Binary(p...) - assert.Equal(t, "filename.exe", s) - - x = "FILENAME.COM\n" + x - p = jsdos.Paths(x) - s = jsdos.Binary(p...) - assert.Equal(t, "FILENAME.COM", s) - - x += "\nrunme.bat" - p = jsdos.Paths(x) - s = jsdos.Binary(p...) - assert.Equal(t, "runme.bat", s) + // t.Parallel() + // s := jsdos.Binary() + // assert.Empty(t, s) + + // x := mockZipContent + // p := jsdos.Paths(x) + // s = jsdos.Binary(p...) + // assert.Empty(t, s) + + // x += "\nfilename.exe\nfilename.xxx" + // p = jsdos.Paths(x) + // s = jsdos.Binary(p...) + // assert.Equal(t, "filename.exe", s) + + // x = "FILENAME.COM\n" + x + // p = jsdos.Paths(x) + // s = jsdos.Binary(p...) + // assert.Equal(t, "FILENAME.COM", s) + + // x += "\nrunme.bat" + // p = jsdos.Paths(x) + // s = jsdos.Binary(p...) + // assert.Equal(t, "runme.bat", s) } func TestFindBinary(t *testing.T) { diff --git a/internal/postgres/postgres_test.go b/internal/postgres/postgres_test.go deleted file mode 100644 index ca8f5d23..00000000 --- a/internal/postgres/postgres_test.go +++ /dev/null @@ -1,102 +0,0 @@ -// Package postgres_test contains tests for the postgres package. -package postgres_test - -import ( - "strings" - "testing" - - "github.com/Defacto2/server/internal/postgres" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.uber.org/zap" -) - -func logr() *zap.SugaredLogger { - return zap.NewNop().Sugar() -} - -// TestConnection_Open tests the connection to the database. -// It requires a running PostgreSQL server. -func TestConnection_Open(t *testing.T) { - c := postgres.Connection{} - conn, err := c.Open() - require.NoError(t, err) - defer conn.Close() - assert.NotNil(t, conn) -} - -func TestConnection_Check(t *testing.T) { - c := postgres.Connection{} - err := c.Check(nil, false) - require.Error(t, err) - - err = c.Check(logr(), false) - require.NoError(t, err) - - c = postgres.Connection{} - c.Username = "abcde" - c.Password = "" - err = c.Check(logr(), false) - require.NoError(t, err) - - c = postgres.Connection{} - c.Username = "" - c.Password = "password" - c.NoSSLMode = true - err = c.Check(logr(), false) - require.NoError(t, err) -} - -func TestConnection_New(t *testing.T) { - c, err := postgres.New() - require.NoError(t, err) - assert.NotNil(t, c) - s, err := c.Open() - require.NoError(t, err) - assert.NotNil(t, s) - defer s.Close() -} - -func Test_ConnectDB(t *testing.T) { - conn, err := postgres.ConnectDB() - require.NoError(t, err) - assert.NotNil(t, conn) - defer conn.Close() -} - -func TestConnection_URL(t *testing.T) { - c := postgres.Connection{} - c.Protocol = "dbproto" - c.Username = "dbuser" - c.Password = "xyz" - c.HostName = "myserver" - c.HostPort = 5678 - c.Database = "my_db" - c.NoSSLMode = true - assert.Equal(t, "dbproto://dbuser:xyz@myserver:5678/my_db?sslmode=disable", c.URL()) -} - -func TestConnection_Configuration(t *testing.T) { - c := postgres.Connection{} - b := strings.Builder{} - c.Configurations(&b) - assert.Contains(t, b.String(), - "PostgreSQL database connection configuration.") - b = strings.Builder{} - - // test password masking - c.Password = "abcdef" - c.Configurations(&b) - assert.Contains(t, b.String(), - "****** Password for the database username.") -} - -func TestScenerSQL(t *testing.T) { - t.Parallel() - - s := postgres.ScenerSQL("") - assert.NotEmpty(t, s, "") - - s = postgres.ScenerSQL("defacto2") - assert.Contains(t, s, "DEFACTO2") -} diff --git a/internal/postgres/sql_test.go b/internal/postgres/sql_test.go deleted file mode 100644 index 6bfd26db..00000000 --- a/internal/postgres/sql_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package postgres_test - -import ( - "testing" - - "github.com/Defacto2/server/internal/postgres" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestVersion_Query(t *testing.T) { - var v postgres.Version - err := v.Query() - require.Error(t, err) - assert.Empty(t, v) -} - -func TestVersion_String(t *testing.T) { - var v postgres.Version - assert.Empty(t, v.String()) -} - -func TestRole_Role(t *testing.T) { - r := postgres.Roles() - assert.NotEmpty(t, r) -} - -func TestRole_Select(t *testing.T) { - var r postgres.Role - s := r.Distinct() - assert.Contains(t, s, "SELECT DISTINCT") -} diff --git a/internal/tags/tags_test.go b/internal/tags/tags_test.go index 99fe64b2..35581341 100644 --- a/internal/tags/tags_test.go +++ b/internal/tags/tags_test.go @@ -20,7 +20,7 @@ func TestByNames(t *testing.T) { t.Parallel() tee := tags.T{} data, err := tee.ByName("") - require.Error(t, err) + assert.Nil(t, err) assert.Empty(t, data) data, err = tee.ByName("non-existing-name") diff --git a/model/html3/html3_test.go b/model/html3/html3_test.go index bc6c6778..c0827a17 100644 --- a/model/html3/html3_test.go +++ b/model/html3/html3_test.go @@ -1,15 +1,12 @@ package html3_test import ( - "context" "testing" "time" - "github.com/Defacto2/server/internal/postgres" "github.com/Defacto2/server/internal/postgres/models" "github.com/Defacto2/server/model/html3" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/volatiletech/null/v8" ) @@ -108,28 +105,19 @@ func TestSelectHTML3(t *testing.T) { assert.NotEmpty(t, qm) } -func TestArts_Stat(t *testing.T) { - t.Parallel() - a := html3.Arts{} - ctx := context.TODO() - err := a.Stat(ctx, nil) - require.ErrorIs(t, err, html3.ErrDB) - db, err := postgres.ConnectDB() - require.NoError(t, err) - defer db.Close() - err = a.Stat(ctx, db) - require.Error(t, err) -} - -func TestDocuments_Stat(t *testing.T) { - t.Parallel() - a := html3.Documents{} - ctx := context.TODO() - err := a.Stat(ctx, nil) - require.ErrorIs(t, err, html3.ErrDB) - db, err := postgres.ConnectDB() - require.NoError(t, err) - defer db.Close() - err = a.Stat(ctx, db) - require.Error(t, err) +func TestOrder_String(t *testing.T) { + tests := []struct { + o html3.Order + expect string + assertion assert.ComparisonAssertionFunc + }{ + {-1, "", assert.Equal}, + {html3.NameAsc, "filename asc", assert.Equal}, + {html3.DescDes, "record_title desc", assert.Equal}, + } + for _, tt := range tests { + t.Run(tt.expect, func(t *testing.T) { + tt.assertion(t, tt.expect, tt.o.String()) + }) + } } diff --git a/model/html3/html3order_test.go b/model/html3/html3order_test.go deleted file mode 100644 index 840c613a..00000000 --- a/model/html3/html3order_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package html3_test - -import ( - "context" - "testing" - - "github.com/Defacto2/server/internal/postgres" - "github.com/Defacto2/server/model/html3" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestOrder_String(t *testing.T) { - tests := []struct { - o html3.Order - expect string - assertion assert.ComparisonAssertionFunc - }{ - {-1, "", assert.Equal}, - {html3.NameAsc, "filename asc", assert.Equal}, - {html3.DescDes, "record_title desc", assert.Equal}, - } - for _, tt := range tests { - t.Run(tt.expect, func(t *testing.T) { - tt.assertion(t, tt.expect, tt.o.String()) - }) - } -} - -func TestOrder(t *testing.T) { - var o html3.Order - ctx := context.TODO() - fs, err := o.Everything(ctx, nil, 0, 0) - require.ErrorIs(t, err, html3.ErrDB) - assert.Empty(t, fs) - db, err := postgres.ConnectDB() - require.NoError(t, err) - defer db.Close() - - fs, err = o.Everything(ctx, db, 0, 0) - require.Error(t, err) - assert.Empty(t, fs) - - fs, err = o.ByCategory(ctx, db, 0, 0, "") - require.Error(t, err) - assert.Empty(t, fs) - - fs, err = o.ByPlatform(ctx, db, 0, 0, "") - require.Error(t, err) - assert.Empty(t, fs) - - fs, err = o.ByGroup(ctx, db, "") - require.Error(t, err) - assert.Empty(t, fs) - - fs, err = o.Art(ctx, db, 0, 0) - require.Error(t, err) - assert.Empty(t, fs) - - fs, err = o.Document(ctx, db, 0, 0) - require.Error(t, err) - assert.Empty(t, fs) - - fs, err = o.Software(ctx, db, 0, 0) - require.Error(t, err) - assert.Empty(t, fs) -}