Skip to content

Commit

Permalink
feat(config): Introduce config environment command
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSchafer committed Jul 16, 2024
1 parent 4c0f6e0 commit 0d8dd2b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/snyk/cli-extension-iac-rules v0.0.0-20240422133948-ae17a4306672
github.com/snyk/cli-extension-sbom v0.0.0-20240619142341-3b3fe79e862c
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1
github.com/snyk/error-catalog-golang-public v0.0.0-20240605115201-8461850930e6
github.com/snyk/go-application-framework v0.0.0-20240627194757-cc0fb551c613
github.com/snyk/error-catalog-golang-public v0.0.0-20240715110939-a528e5c7d26d
github.com/snyk/go-application-framework v0.0.0-20240716082832-a722d639217c
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20240715053529-8f015d9f14f0
Expand Down
8 changes: 4 additions & 4 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,10 @@ github.com/snyk/code-client-go v1.8.0 h1:6H883KAn7ybiSIxhvL2QR9yEyHgAwA2+9WVHMDN
github.com/snyk/code-client-go v1.8.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s=
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 h1:9RKY9NdX5DrJAoVXDP0JiqrXT+4Nb9NH8pjEcA0NsLA=
github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/error-catalog-golang-public v0.0.0-20240605115201-8461850930e6 h1:0t2lDRZY9zn/zgmY9sbRZ4WZFFR+7lIV/4+CMPUhJOs=
github.com/snyk/error-catalog-golang-public v0.0.0-20240605115201-8461850930e6/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20240627194757-cc0fb551c613 h1:igHAJ85dfn9cR1onRbpe4a9Mex1/Oo4PUxJfNPaWle0=
github.com/snyk/go-application-framework v0.0.0-20240627194757-cc0fb551c613/go.mod h1:gz3PN/OfEBbtB4VxbnV33XipM8MjBcVszPJeOhCu2DU=
github.com/snyk/error-catalog-golang-public v0.0.0-20240715110939-a528e5c7d26d h1:LtvOq6MD7Tei0xx0/41AMiDD5jfvjgJ7xGp7e9PL9fY=
github.com/snyk/error-catalog-golang-public v0.0.0-20240715110939-a528e5c7d26d/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20240716082832-a722d639217c h1:YFjWoOvvyBgOWrOrAFsB9A9LHbV0+S3c4gENWRS1p94=
github.com/snyk/go-application-framework v0.0.0-20240716082832-a722d639217c/go.mod h1:X7PyPo6Vuf+nlxkHmqvhg0suwHmx+I2quCNKFHdaHp4=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.30.11 h1:wUy5LMar2vccMbNM62MSBRdjAQAhAbIm7aNXXO+g2tk=
Expand Down
47 changes: 47 additions & 0 deletions test/jest/acceptance/snyk-config/snyk-config-environment.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { runSnykCLI } from '../../util/runSnykCLI';
import {
getCliConfig,
restoreCliConfig,
} from '../../../acceptance/config-helper';

jest.setTimeout(1000 * 30);

describe('snyk config environment', () => {
let initialConfig: Record<string, string> = {};

beforeEach(async () => {
initialConfig = await getCliConfig();
});

afterEach(async () => {
await restoreCliConfig(initialConfig);
});

it('successfully configure with a partial DNS name', async () => {
const { code, stderr } = await runSnykCLI(`config environment dev`);
expect(stderr).toEqual('');
expect(code).toEqual(0);

const { stdout } = await runSnykCLI(`config get endpoint`);
expect(stdout.trim()).toEqual('https://api.dev.snyk.io');
});

it('successfully configure with a URL', async () => {
const { code, stderr } = await runSnykCLI(
`config environment https://api.dev.snyk.io`,
);
expect(stderr).toEqual('');
expect(code).toEqual(0);

const { stdout } = await runSnykCLI(`config get endpoint`);
expect(stdout.trim()).toEqual('https://api.dev.snyk.io');
});

it('fail with an invalid env alias', async () => {
const { code, stderr } = await runSnykCLI(
`config environment randomEnvName`,
);
expect(stderr).toEqual('');
expect(code).toEqual(2);
});
});

0 comments on commit 0d8dd2b

Please sign in to comment.