Skip to content

FirstRun First Test

Bert Kleewein edited this page Feb 19, 2020 · 3 revisions

Running Your First Test

Step 1: Deploy containers and create azure objects needed for tests

We're going to use the horton deploy script to deploy objects. This creates docker containers with the code we're testing and it also creates Azure resources (e.g. IoTHub devices and modules) used by the tests.

We're going to use the node.js SDK for this example, you can replace the word "node" in the image name to test with a different SDK.

On Windows, run horton deploy iothub --image %IOTHUB_E2E_REPO_ADDRESS%/node-e2e-v3:lkg On Linux, run horton deploy iothub --image $IOTHUB_E2E_REPO_ADDRESS/node-e2e-v3:lkg

Step 2: Verify deployment

You should be able to run docker ps and see the code you're testing running. This will always be called testMod, even if you're not testing IoTHub or IoTEdge modules:

(horton) F:\repos\e2e-fx>docker ps
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS              PORTS                                                                            NAMES
1cab542767a8        <REDACTED>/node-e2e-v3:lkg             "/usr/local/bin/node…"   5 minutes ago       Up 5 minutes        9229/tcp, 0.0.0.0:8199->22/tcp, 0.0.0.0:8140->8040/tcp, 0.0.0.0:8099->8080/tcp   testMod
7f5236258e4a        registry:2                             "/entrypoint.sh /etc…"   52 minutes ago      Up 52 minutes       0.0.0.0:5000->5000/tcp                                                           registry

(horton) F:\repos\e2e-fx>

Step 3: Look at the test settings

This step is purely informational. The test settings are stored in _horton_settings.json in the root of your clone. At this point, you can see the names of devices and modules that Horton will use.

{
  "iothub": {
    "connection_string": "<REDACTED>"
  },
  "test_module": {
    "adapter_address": "http://localhost:8099",
    "connection_type": "connection_string",
    "container_name": "testMod",
    "container_port": 8080,
    "device_id": "BERTK_GRP_218_test_device",
    "host_port": 8099,
    "image": "<REDACTED>/node-e2e-v3:lkg",
    "language": "node",
    "module_id": "testMod"
  },
  "test_device": {
    "adapter_address": "http://localhost:8099",
    "connection_type": "connection_string",
    "container_name": "testMod",
    "container_port": 8080,
    "device_id": "BERTK_GRP_218_test_device",
    "host_port": 8099,
    "image": "<REDACTED>/node-e2e-v3:lkg",
    "language": "node"
  },
  "net_control": {
    "adapter_address": "http://localhost:8140",
    "container_port": 8040,
    "host_port": 8140,
    "test_destination": "<REDACTED>"
  },
  "horton": {
    "image": "<REDACTED>/node-e2e-v3:lkg"
  }
}

Step 4: Get credentials

Run Horton get_credentials to add connection credentials to _horton_settings.json

(horton) F:\repos\e2e-fx>horton get_credentials
Added connection string for test_device device BERTK_GRP_218_test_device
Added connection string for test_module module BERTK_GRP_218_test_device,testMod

(horton) F:\repos\e2e-fx>

After you do this, you should see connection strings inside your _horton_settings.json file.

<<--SNIP-->>
  "test_module": {
    "adapter_address": "http://localhost:8099",
    "connection_string": "HostName=<REDACTED>;DeviceId=BERTK_GRP_218_test_device;ModuleId=testMod;SharedAccessKey=<REDACTED>",
    "connection_type": "connection_string",
    "container_name": "testMod",
<<--SNIP-->>

Step 5: Run the tests

To run the tests, run pytest --scneario=iothub_module in the test-runner directory.

The invalid status code 'Not Found' warnings are OK to ignore

F:\repos\e2e-fx\test-runner>pytest --scenario=iothub_module
============================= test session starts =============================
<<--snip-->>
==================== 7 passed, 11 skipped in 50.23 seconds ====================

Some notes on this run:

  1. If you're running on Linux, you should be able to test IoTEdge by replacing the word iothub with iotedge in the horton deploy command line.
  2. If you want to see more output when running the tests, add -s to your pytest command line.
  3. If you want to see full output from your SDK, open a new window and run docker logs -f testMod
Clone this wiki locally