Skip to content

Commit

Permalink
Regression tests (#142)
Browse files Browse the repository at this point in the history
* added typescript tests to meraki provider. This is not a full test suite.

* add get-devices, network-base-ts, network-settings-ts,
network-appliance-vlans-settings-ts, network-alert-settings-ts,
and network-appliance-content-filter-ts tests

add test_nodejs to makefile

* Set secrets

---------

Co-authored-by: phillip edwards <[email protected]>
Co-authored-by: zbuchheit <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2024
1 parent 2a81549 commit 27bd162
Show file tree
Hide file tree
Showing 117 changed files with 2,157 additions and 457 deletions.
4 changes: 4 additions & 0 deletions .ci-mgmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ plugins:
team: ecosystem
providerDefaultBranch: main

env:
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}

actions:
preTest:
- name: make upstream
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/command-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
env:
IS_PRERELEASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prerequisites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ on:
env:
IS_PRERELEASE: ${{ inputs.isPrerelease }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/resync-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ env:
PULUMI_EXTRA_MAPPING_ERROR: true
PULUMI_MISSING_MAPPING_ERROR: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
env:
PR_COMMIT_SHA: ${{ github.event.client_payload.pull_request.head.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ on:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERAKI_DASHBOARD_API_KEY: ${{ secrets.MERAKI_DASHBOARD_API_KEY }}
MERAKI_ORG_ID: ${{ secrets.MERAKI_ORG_ID }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NUGET_PUBLISH_KEY: ${{ secrets.NUGET_PUBLISH_KEY }}
Expand Down
75 changes: 61 additions & 14 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,77 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
// Copyright 2016-2024, Pulumi Corporation. All rights reserved.
//go:build nodejs || all
// +build nodejs all

package examples

import (
"os"
"path/filepath"
"testing"

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/opttest"
)

func TestAccRecordTs(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "org-policy-groups", "ts"),
})
func TestGetDevicesTs(t *testing.T) {
t.Skip("Skipping Pulumi Test as this currently doesn't work. See https://github.com/pulumi/pulumi-meraki/issues/134 for more details")
checkBaseEnvVars(t)
test := pulumitest.NewPulumiTest(t, "get-devices-ts",
opttest.LocalProviderPath("meraki", filepath.Join(getCwd(t), "..", "bin")),
)
test.SetConfig("organizationId", os.Getenv(EnvMerakiOrgID))
test.Preview()
}
func TestNetworkBaseTs(t *testing.T) {
checkBaseEnvVars(t)
test := pulumitest.NewPulumiTest(t, "network-base-ts",
opttest.LocalProviderPath("meraki", filepath.Join(getCwd(t), "..", "bin")),
opttest.YarnLink("@pulumi/meraki"),
)
test.SetConfig("organizationId", os.Getenv(EnvMerakiOrgID))
test.SetConfig("networkName", "Pulumi Base Test Network_" + randomString(6))
test.Up()
}

integration.ProgramTest(t, &test)
func TestNetworkSettingsTs(t *testing.T) {
checkBaseEnvVars(t)
test := pulumitest.NewPulumiTest(t, "network-settings-ts",
opttest.LocalProviderPath("meraki", filepath.Join(getCwd(t), "..", "bin")),
opttest.YarnLink("@pulumi/meraki"),
)
test.SetConfig("organizationId", os.Getenv(EnvMerakiOrgID))
test.SetConfig("networkName", "Pulumi Base Test Network_" + randomString(6))
test.Up()
}

func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
base := getBaseOptions(t)
baseJS := base.With(integration.ProgramTestOptions{
Dependencies: []string{"@pulumi/meraki"},
})
func TestApplianceVlansTs(t *testing.T) {
checkBaseEnvVars(t)
test := pulumitest.NewPulumiTest(t, "network-appliance-vlans-ts",
opttest.LocalProviderPath("meraki", filepath.Join(getCwd(t), "..", "bin")),
opttest.YarnLink("@pulumi/meraki"),
)
test.SetConfig("organizationId", os.Getenv(EnvMerakiOrgID))
test.SetConfig("networkName", "Pulumi Base Test Network_" + randomString(6))
test.Up()
}

return baseJS
func TestAlertSettingsTs(t *testing.T) {
checkBaseEnvVars(t)
test := pulumitest.NewPulumiTest(t, "network-alert-settings-ts",
opttest.LocalProviderPath("meraki", filepath.Join(getCwd(t), "..", "bin")),
opttest.YarnLink("@pulumi/meraki"),
)
test.SetConfig("organizationId", os.Getenv(EnvMerakiOrgID))
test.SetConfig("networkName", "Pulumi Base Test Network_" + randomString(6))
test.Up()
}
func TestApplianceContentFilterTs(t *testing.T) {
checkBaseEnvVars(t)
test := pulumitest.NewPulumiTest(t, "network-appliance-content-filtering-ts",
opttest.LocalProviderPath("meraki", filepath.Join(getCwd(t), "..", "bin")),
opttest.YarnLink("@pulumi/meraki"),
)
test.SetConfig("organizationId", os.Getenv(EnvMerakiOrgID))
test.SetConfig("networkName", "Pulumi Base Test Network_" + randomString(6))
test.Up()
}
32 changes: 23 additions & 9 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
// Copyright 2016-2024, Pulumi Corporation. All rights reserved.

package examples

import (
"math/rand"
"os"
"testing"
)

"github.com/pulumi/pulumi/pkg/v3/testing/integration"
const (
EnvMerakiAPIKey = "MERAKI_DASHBOARD_API_KEY"
EnvMerakiOrgID = "MERAKI_ORG_ID"
)

func merakiApiKey(t *testing.T) {
const env = "MERAKI_DASHBOARD_API_KEY"
if key := os.Getenv(env); key == "" {
t.Skipf("Skipping test due to missing %s environment variable", env)
func checkEnvVars(t *testing.T, envVar string) {
value := os.Getenv(envVar)
if value == "" {
t.Skipf("Skipping test due to missing %s environment variable", envVar)
}
}

Expand All @@ -25,7 +29,17 @@ func getCwd(t *testing.T) string {
return cwd
}

func getBaseOptions(t *testing.T) integration.ProgramTestOptions {
merakiApiKey(t)
return integration.ProgramTestOptions{}
var letterRunes = []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randomString(length int) string {
b := make([]rune, length)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}

func checkBaseEnvVars(t *testing.T) {
checkEnvVars(t, EnvMerakiOrgID)
checkEnvVars(t, EnvMerakiAPIKey)
}
3 changes: 3 additions & 0 deletions examples/get-devices-ts/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: meraki-get-devices-ts
runtime: nodejs
description: A minimal TypeScript Pulumi program
10 changes: 10 additions & 0 deletions examples/get-devices-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as pulumi from "@pulumi/pulumi";
import * as meraki from "@pulumi/meraki";

export = async () => {
const config = new pulumi.Config();
const organizationId = config.require("organizationId");
await meraki.getDevices({
organizationId,
});
};
12 changes: 12 additions & 0 deletions examples/get-devices-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "meraki-get-devices-ts",
"main": "index.ts",
"devDependencies": {
"@types/node": "^18",
"typescript": "^5.0.0"
},
"dependencies": {
"@pulumi/meraki": "^0.2.10",
"@pulumi/pulumi": "^3.113.0"
}
}
16 changes: 16 additions & 0 deletions examples/get-devices-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.ts"]
}
Loading

0 comments on commit 27bd162

Please sign in to comment.