Skip to content

Commit

Permalink
remove more test code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tze Yang Ng committed Mar 2, 2024
1 parent 43c6c88 commit 22ab0d0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 66 deletions.
42 changes: 0 additions & 42 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,6 @@ func SetUpClients(conf *viper.Viper) *Clients {
return &clients
}

func SetUpTestClients(t *testing.T, conf *viper.Viper) *Clients {
postgresClient, err := InitializePostgresClient(conf)
if err != nil {
panic(fmt.Errorf("starting postgres client failed: %v", err))

}

// Create server
config := nomad.DefaultConfig()
ns := testutil.NewTestServer(t, nil)
config.Address = "http://" + ns.HTTPAddr

// Create client
client, err := nomad.NewClient(config)
if err != nil {
panic(fmt.Errorf("starting nomad client failed: %v", err))
}
nc := NomadClient{
nc: client,
conf: conf,
}

// caching fields
dockerTags := sync.Map{}
digestMap := sync.Map{}
for _, repoName := range conf.GetStringSlice("watched_repositories") {
dockerTags.Store(repoName, []string{})
digestMap.Store(repoName, "")
}

clients := Clients{
NomadClient: &nc,
NomadServer: ns,
PostgresClient: postgresClient,
DockerRegistryClient: InitializeDockerRegistryClient(conf),
DockerhubApi: nil,
DockerTags: dockerTags,
DigestMap: digestMap,
}
return &clients
}

func (client *Clients) GetCachedTags(repoName string) ([]string, error) {
rtn, ok := client.DockerTags.Load(repoName)
if !ok {
Expand Down
22 changes: 2 additions & 20 deletions client/docker_registry_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package client

import (
"fmt"

"github.com/dsaidgovsg/registrywatcher/registry"
"github.com/dsaidgovsg/registrywatcher/utils"
"github.com/spf13/viper"
"path/filepath"
"runtime"
)

type DockerRegistryClient struct {
Expand All @@ -15,19 +14,6 @@ type DockerRegistryClient struct {
}

func InitializeDockerRegistryClient(conf *viper.Viper) *DockerRegistryClient {

test := conf.GetBool("is_test")
var cert string
var key string
if test {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic(fmt.Errorf("no caller information"))
}
cert = filepath.Join(filepath.Dir(filepath.Dir(filename)), "testutils", "snakeoil", "cert.pem")
key = filepath.Join(filepath.Dir(filepath.Dir(filename)), "testutils", "snakeoil", "key.pem")
}

watchedRepositories := conf.GetStringSlice("watched_repositories")
drc := DockerRegistryClient{
Hubs: make(map[string]registry.Registry, len(watchedRepositories)),
Expand All @@ -41,11 +27,7 @@ func InitializeDockerRegistryClient(conf *viper.Viper) *DockerRegistryClient {
}
scope := fmt.Sprintf("repository:%s/%s:pull,push", registryPrefix, repoName)
var hub *registry.Registry
if test {
hub, err = registry.NewSecure(registryUrl, scope, username, password, cert, key)
} else {
hub, err = registry.New(registryUrl, scope, username, password)
}
hub, err = registry.New(registryUrl, scope, username, password)
if err != nil {
panic(fmt.Errorf("starting docker registry client failed: %v", err))
}
Expand Down
6 changes: 2 additions & 4 deletions utils/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//go:build unit
// +build unit

package utils

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestTagToNumber(t *testing.T) {
Expand Down

0 comments on commit 22ab0d0

Please sign in to comment.