Make unit tests work

This commit is contained in:
Christopher LaPointe
2023-06-03 16:19:56 -04:00
parent acc5172ae6
commit 6c8e52d24e
6 changed files with 41 additions and 7 deletions

View File

@@ -6,10 +6,10 @@ via traefik.
## How it Works ## How it Works
It works by acting as the fallback-route for the containers. For instance, if you have It works by acting as the fallback-route for the containers. For instance, if you have
`example.com` as a container you want to lazy-load, you would add the container, as well `example.com` as a container you want to lazy-load, you add the container, as well
as this lazyloader that would act as a lower-priority router for the same domain. If the as this lazyloader that would act as a lower-priority router for the same route. If the
host is accessed, the lazyloader will work to boot up the container and redirect the user host is accessed, the lazyloader will work to boot up the container and redirect the user
as soon as it's up. as soon as it's responsive.
It then monitors the container's network interface. If the network is idle for X minutes, it It then monitors the container's network interface. If the network is idle for X minutes, it
will stop the container. will stop the container.
@@ -21,7 +21,7 @@ will stop the container.
version: '3.5' version: '3.5'
services: services:
# Example traefik proxy # Example traefik proxy (Don't need if you already have something set up!)
reverse-proxy: reverse-proxy:
image: traefik:v2.4 image: traefik:v2.4
command: command:
@@ -73,7 +73,7 @@ You can run `docker-compose up` on the above for a quick-start. You will need to
## Config ## Config
Configuration uses [viper]() and can be specified by either overwriting the `config.yaml` file or Configuration uses [viper](https://github.com/spf13/viper) and can be specified by either overwriting the `config.yaml` file or
via environment variables with the `TLL_` prefix (Traefik lazy loader) via environment variables with the `TLL_` prefix (Traefik lazy loader)
```yaml ```yaml
@@ -103,6 +103,8 @@ labelprefix: lazyloader
## Labels ## Labels
Use these on containers you want to be lazy-loaded.
* `lazyloader=true` -- (Required) Add to containers that should be managed * `lazyloader=true` -- (Required) Add to containers that should be managed
* `lazyloader.stopdelay=5m` -- Amount of time to wait for idle network traffick before stopping a container * `lazyloader.stopdelay=5m` -- Amount of time to wait for idle network traffick before stopping a container
* `lazyloader.waitforcode=200` -- Waits for this HTTP result from downstream before redirecting user. Can be comma-separated list * `lazyloader.waitforcode=200` -- Waits for this HTTP result from downstream before redirecting user. Can be comma-separated list
@@ -118,4 +120,17 @@ labelprefix: lazyloader
# License # License
GPLv3 Copyright (C) 2023 Christopher LaPointe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

3
go.mod
View File

@@ -10,6 +10,7 @@ require (
require ( require (
github.com/Microsoft/go-winio v0.6.1 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect github.com/docker/go-units v0.5.0 // indirect
@@ -24,10 +25,12 @@ require (
github.com/opencontainers/image-spec v1.0.2 // indirect github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.3 // indirect github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/mod v0.8.0 // indirect golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.6.0 // indirect golang.org/x/net v0.6.0 // indirect

2
go.sum
View File

@@ -191,6 +191,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View File

@@ -33,6 +33,8 @@ func mustCreateDockerClient() *client.Client {
} }
func main() { func main() {
config.Load()
if config.Model.Verbose { if config.Model.Verbose {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
logrus.Debug("Verbose is on") logrus.Debug("Verbose is on")

View File

@@ -28,7 +28,7 @@ type ConfigModel struct {
var Model *ConfigModel = new(ConfigModel) var Model *ConfigModel = new(ConfigModel)
func init() { func Load() {
viper.AddConfigPath(".") viper.AddConfigPath(".")
viper.SetConfigName("config") viper.SetConfigName("config")
viper.SetConfigType("yaml") viper.SetConfigType("yaml")

View File

@@ -0,0 +1,12 @@
package containers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSliceContainers(t *testing.T) {
assert.True(t, strSliceContains([]string{"hello", "thar"}, "thar"))
assert.False(t, strSliceContains([]string{"hello", "thar"}, "th"))
}