Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix broken tests #719

Merged
merged 15 commits into from
May 18, 2024
8 changes: 4 additions & 4 deletions .github/workflows/ci-build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:

steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install python dependencies
Expand All @@ -40,10 +40,10 @@ jobs:
- name: running codespell
run: codespell --skip="vendor,*.git,*.png,*.pdf,*.tiff,*.plist,*.pem,rangesim*.go,*.gz,go.mod,go.sum" --ignore-words="./testdata/ignore_words.txt"

- uses: actions/setup-go@v1
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v2
- uses: actions/checkout@v4

name: Get dependencies
- run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -61,4 +61,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
4 changes: 2 additions & 2 deletions .github/workflows/publish-beta-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
run: echo "baretag=$(echo ${{ github.ref }} | cut -b 12-)" >> "$GITHUB_OUTPUT"
#
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
#
- name: install golang
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build project
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-release-candidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
run: echo "baretag=$(echo ${{ github.ref }} | cut -b 12-)" >> "$GITHUB_OUTPUT"
#
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
#
- name: install golang
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: "1.22"
#
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
run: echo "baretag=$(echo ${{ github.ref }} | cut -b 12-)" >> "$GITHUB_OUTPUT"
#
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
#
- name: install golang
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: "1.22"
#
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ out.log

tags

# file copies that should not be committed to the repo
*.old
*.copy

# any generated test cert/keys that testing did not cleanup due to user abort
.pem

Expand Down
14 changes: 6 additions & 8 deletions cmd/trickster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
"os"
"sync"

"github.com/trickstercache/trickster/v2/pkg/runtime"
"github.com/trickstercache/trickster/v2/pkg/appinfo"
"github.com/trickstercache/trickster/v2/pkg/httpserver"
)

var (
Expand All @@ -34,14 +35,11 @@ const (
applicationVersion = "2.0.0-beta2"
)

var wg = &sync.WaitGroup{}

var exitFunc func() = exitFatal

func main() {
runtime.ApplicationName = applicationName
runtime.ApplicationVersion = applicationVersion
runConfig(nil, wg, nil, nil, os.Args[1:], exitFunc)
wg := &sync.WaitGroup{}
appinfo.SetAppInfo(applicationName, applicationVersion,
applicationBuildTime, applicationGitCommitID)
httpserver.Serve(nil, wg, nil, nil, os.Args[1:], exitFatal)
wg.Wait()
}

Expand Down
38 changes: 0 additions & 38 deletions cmd/trickster/main_test.go

This file was deleted.

10 changes: 5 additions & 5 deletions cmd/trickster/usage.go → cmd/trickster/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

package main
package usage

import (
"fmt"
goruntime "runtime"

"github.com/trickstercache/trickster/v2/pkg/runtime"
"github.com/trickstercache/trickster/v2/pkg/appinfo"
)

const usageText = `
Expand Down Expand Up @@ -76,16 +76,16 @@ func version() string {
os := goruntime.GOOS
// use an empty string for goVer, arch, and os during unit tests
// to accommodate rigid tests like ExamplePrintVersion and ExamplePrintUsage
if runtime.ApplicationVersion == "test" {
if appinfo.Version == "test" {
goVer = ""
arch = ""
os = ""
}

return fmt.Sprintf("Trickster version: %s (%s/%s), buildInfo: %s %s, goVersion: %s, copyright: © 2018 The Trickster Authors",
runtime.ApplicationVersion,
appinfo.Version,
os, arch,
applicationBuildTime, applicationGitCommitID,
appinfo.BuildTime, appinfo.GitCommitID,
goVer,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
* limitations under the License.
*/

package main
package usage

import (
"github.com/trickstercache/trickster/v2/pkg/runtime"
"github.com/trickstercache/trickster/v2/pkg/appinfo"
)

// ExamplePrintVersion tests the output of the PrintVersion() func
func ExamplePrintVersion() {
runtime.ApplicationVersion = "test"
appinfo.Version = "test"
PrintVersion()
// Output: Trickster version: test (/), buildInfo: , goVersion: , copyright: © 2018 The Trickster Authors
}

// ExamplePrintUsage tests the output of the PrintUsage() func
func ExamplePrintUsage() {

runtime.ApplicationVersion = "test"
appinfo.Version = "test"
PrintUsage()
// Output: Trickster version: test (/), buildInfo: , goVersion: , copyright: © 2018 The Trickster Authors
//
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/trickstercache/trickster/v2

go 1.22

toolchain go1.22.3

require (
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/andybalholm/brotli v1.1.0
Expand Down
29 changes: 23 additions & 6 deletions pkg/runtime/runtime.go → pkg/appinfo/appinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,34 @@
* limitations under the License.
*/

// Package runtime holds application runtime information
package runtime
// Package app holds application build information
package appinfo

import "os"

// ApplicationName is the name of the Application
var ApplicationName string
// Name is the name of the Application
var Name string

// ApplicationVersion holds the version of the Application
var ApplicationVersion string
// Version holds the version of the Application
var Version string

// BuildTime is the Time that the Application was Built
var BuildTime string

// GitCommitID holds the Git Commit ID of the current binary/build
var GitCommitID string

// Server is the name, hostname or ip of the server as advertised in HTTP Headers
// By default uses the hostname reported by the kernel
var Server, _ = os.Hostname()

func SetAppInfo(name, version, buildTime, gitCommitID string) {
Name = name
Version = version
BuildTime = buildTime
GitCommitID = gitCommitID
}

func SetServer(server string) {
Server = server
}
6 changes: 3 additions & 3 deletions pkg/backends/alb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package alb

import (
"errors"
"fmt"
"net/http"
"strings"
Expand All @@ -29,6 +28,7 @@ import (
"github.com/trickstercache/trickster/v2/pkg/backends/providers"
"github.com/trickstercache/trickster/v2/pkg/backends/providers/registration/types"
"github.com/trickstercache/trickster/v2/pkg/cache"
"github.com/trickstercache/trickster/v2/pkg/errors"
"github.com/trickstercache/trickster/v2/pkg/proxy/methods"
"github.com/trickstercache/trickster/v2/pkg/proxy/paths/matching"
po "github.com/trickstercache/trickster/v2/pkg/proxy/paths/options"
Expand Down Expand Up @@ -157,7 +157,7 @@ func (c *Client) ValidatePool(clients backends.Backends) error {
// validate and map out the pool configuration
func (c *Client) ValidateAndStartPool(clients backends.Backends, hcs healthcheck.StatusLookup) error {
if c.Configuration() == nil || c.Configuration().ALBOptions == nil {
return errors.New("invalid options")
return errors.ErrInvalidOptions
}

o := c.Configuration().ALBOptions
Expand All @@ -172,7 +172,7 @@ func (c *Client) ValidateAndStartPool(clients backends.Backends, hcs healthcheck
if !ok {
return fmt.Errorf("invalid pool member name [%s] in backend [%s]", n, c.Name())
}
hc, _ := hcs[n]
hc := hcs[n]
targets = append(targets, pool.NewTarget(tc.Router(), hc))
}
c.pool = pool.New(m, targets, o.HealthyFloor)
Expand Down
8 changes: 4 additions & 4 deletions pkg/backends/alb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ func TestHandlers(t *testing.T) {
}

a.MechanismName = "fgr"
cl, err = NewClient("test", o, nil, nil, nil, nil)
_, err = NewClient("test", o, nil, nil, nil, nil)
if err != nil {
t.Error(err)
}

a.MechanismName = "nlm"
cl, err = NewClient("test", o, nil, nil, nil, nil)
_, err = NewClient("test", o, nil, nil, nil, nil)
if err != nil {
t.Error(err)
}

a.MechanismName = "tsm"
cl, err = NewClient("test", o, nil, nil, nil, types.Lookup{"prometheus": prometheus.NewClient})
_, err = NewClient("test", o, nil, nil, nil, types.Lookup{"prometheus": prometheus.NewClient})
if err != nil {
t.Error(err)
}

a.MechanismName = "rr"
cl, err = NewClient("test", o, nil, nil, nil, nil)
_, err = NewClient("test", o, nil, nil, nil, nil)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"net/url"
"testing"

"github.com/trickstercache/trickster/v2/cmd/trickster/config"
bo "github.com/trickstercache/trickster/v2/pkg/backends/options"
cr "github.com/trickstercache/trickster/v2/pkg/cache/registration"
"github.com/trickstercache/trickster/v2/pkg/config"
tl "github.com/trickstercache/trickster/v2/pkg/observability/logging"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"net/url"
"testing"

"github.com/trickstercache/trickster/v2/cmd/trickster/config"
"github.com/trickstercache/trickster/v2/pkg/backends"
"github.com/trickstercache/trickster/v2/pkg/backends/clickhouse/model"
bo "github.com/trickstercache/trickster/v2/pkg/backends/options"
cr "github.com/trickstercache/trickster/v2/pkg/cache/registration"
"github.com/trickstercache/trickster/v2/pkg/config"
tl "github.com/trickstercache/trickster/v2/pkg/observability/logging"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/influxdb/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package influxdb
import (
"testing"

"github.com/trickstercache/trickster/v2/cmd/trickster/config"
"github.com/trickstercache/trickster/v2/pkg/backends"
"github.com/trickstercache/trickster/v2/pkg/backends/influxdb/model"
bo "github.com/trickstercache/trickster/v2/pkg/backends/options"
cr "github.com/trickstercache/trickster/v2/pkg/cache/registration"
"github.com/trickstercache/trickster/v2/pkg/config"
tl "github.com/trickstercache/trickster/v2/pkg/observability/logging"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/backends/influxdb/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"testing"
"time"

"github.com/trickstercache/trickster/v2/cmd/trickster/config"
"github.com/trickstercache/trickster/v2/pkg/config"
"github.com/trickstercache/trickster/v2/pkg/proxy/headers"
"github.com/trickstercache/trickster/v2/pkg/proxy/params"
"github.com/trickstercache/trickster/v2/pkg/timeseries"
Expand Down
4 changes: 1 addition & 3 deletions pkg/backends/irondb/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func TestDefaultHealthCheckConfig(t *testing.T) {
dho := c.DefaultHealthCheckConfig()
if dho == nil {
t.Error("expected non-nil result")
}

if dho.Path != "" {
} else if dho.Path != "" {
t.Error("expected / for path", dho.Path)
}

Expand Down
Loading
Loading