Skip to content

Commit

Permalink
eliminate the need for TLS certs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Aug 28, 2024
1 parent 73357b9 commit 05ba0c8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 182 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
Expand All @@ -27,9 +24,6 @@ jobs:
- name: Install juju-db
run: sudo snap install juju-db --channel 4.4/stable

- name: Create test certs
run: make certs

- name: Start test environment
run: docker compose up -d --wait

Expand All @@ -40,11 +34,3 @@ jobs:

- name: Build and Test
run: go test -mod readonly ./... -timeout 1h -cover
env:
JIMM_DSN: postgresql://jimm:jimm@localhost:5432/jimm
JIMM_TEST_PGXDSN: postgresql://jimm:jimm@localhost:5432/jimm
PGHOST: localhost
PGPASSWORD: jimm
PGSSLMODE: disable
PGUSER: jimm
PGPORT: 5432
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clean:
certs:
@cd local/traefik/certs; ./certs.sh; cd -

test-env: sys-deps certs
test-env: sys-deps
@docker compose up --force-recreate -d --wait

test-env-cleanup:
Expand Down
176 changes: 57 additions & 119 deletions cmd/jimmctl/cmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/juju/juju/cloud"
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/jujuclient"

"github.com/canonical/jimm/v3/internal/cmdtest"
)

var (
Expand All @@ -20,61 +22,54 @@ var (

type AccessResult = accessResult

func testDialOpts(lp jujuapi.LoginProvider) *jujuapi.DialOpts {
return &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
DialWebsocket: cmdtest.GetDialWebsocketWithInsecureUrl(),
}
}

func NewListControllersCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &listControllersCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewModelStatusCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &modelStatusCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewGrantAuditLogAccessCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &grantAuditLogAccessCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewRevokeAuditLogAccessCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &revokeAuditLogAccessCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewListAuditEventsCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &listAuditEventsCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
Expand All @@ -84,10 +79,7 @@ func NewAddCloudToControllerCommandForTesting(store jujuclient.ClientStore, lp j
cmd := &addCloudToControllerCommand{
store: store,
cloudByNameFunc: cloudByNameFunc,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
Expand All @@ -97,11 +89,8 @@ type RemoveCloudFromControllerAPI = removeCloudFromControllerAPI

func NewRemoveCloudFromControllerCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider, removeCloudFromControllerAPIFunc func() (RemoveCloudFromControllerAPI, error)) cmd.Command {
cmd := &removeCloudFromControllerCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
removeCloudFromControllerAPIFunc: removeCloudFromControllerAPIFunc,
}
if removeCloudFromControllerAPIFunc == nil {
Expand All @@ -113,23 +102,17 @@ func NewRemoveCloudFromControllerCommandForTesting(store jujuclient.ClientStore,

func NewAddControllerCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &addControllerCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewRemoveControllerCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &removeControllerCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
Expand All @@ -145,179 +128,134 @@ func NewControllerInfoCommandForTesting(store jujuclient.ClientStore) cmd.Comman

func NewSetControllerDeprecatedCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &setControllerDeprecatedCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewImportModelCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &importModelCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewUpdateMigratedModelCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &updateMigratedModelCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewImportCloudCredentialsCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &importCloudCredentialsCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewAddGroupCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &addGroupCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewRenameGroupCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &renameGroupCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewRemoveGroupCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &removeGroupCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewListGroupsCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &listGroupsCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewAddRelationCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &addRelationCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewRemoveRelationCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &removeRelationCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewListRelationsCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &listRelationsCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewCheckRelationCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &checkRelationCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewCrossModelQueryCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &crossModelQueryCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewPurgeLogsCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &purgeLogsCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
}

func NewMigrateModelCommandForTesting(store jujuclient.ClientStore, lp jujuapi.LoginProvider) cmd.Command {
cmd := &migrateModelCommand{
store: store,
dialOpts: &jujuapi.DialOpts{
InsecureSkipVerify: true,
LoginProvider: lp,
},
store: store,
dialOpts: testDialOpts(lp),
}

return modelcmd.WrapBase(cmd)
Expand Down
Loading

0 comments on commit 05ba0c8

Please sign in to comment.