Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/xxx/additional tests #9

Merged
merged 20 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ jobs:
done
- name: Test
run: make test
go-lint:
runs-on:
group: large-runners
go-test-wago:
runs-on: hercules
timeout-minutes: 30
steps:
- name: Checkout
Expand All @@ -59,11 +58,8 @@ jobs:
uses: ./.github/actions/setup-go
with:
go_version: ${{ env.GO_VERSION }}
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.49
args: --timeout 30m -v
- name: Test
run: TEST_WAGO_ENDPOINT_URI=${{ secrets.TEST_WAGO_ENDPOINT_URI }} TEST_WAGO_USERNAME=${{ secrets.TEST_WAGO_USERNAME }} TEST_WAGO_PASSWORD=${{ secrets.TEST_WAGO_PASSWORD }} make test
go-build:
runs-on:
group: large-runners
Expand Down Expand Up @@ -96,17 +92,6 @@ jobs:
name: benthos
path: tmp/bin/benthos
retention-days: 2
lint:
runs-on:
group: large-runners
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Lint
run: npm run lint
build:
runs-on:
group: large-runners
Expand Down
28 changes: 26 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- before: |
curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.gpg | sudo apt-key add - \
&& curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/focal.list | sudo tee /etc/apt/sources.list.d/tailscale.list \
&& sudo apt-get update -q \
&& sudo apt-get install -yq tailscale jq \
&& sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-nft
- init: |
nvm install
npm install
Expand All @@ -13,11 +19,29 @@ tasks:
sudo apt update
sudo apt install goreleaser --yes
make
command:
- command: |
gp sync-await docker
npm run lint
make test
- command: cd tests
- command: |
cd tests
docker-compose up -d
sleep 5
gp sync-done docker
- name: tailscaled
command: |
if [ -n "${TAILSCALE_STATE_MYPROJECT}" ]; then
# restore the tailscale state from gitpod user's env vars
sudo mkdir -p /var/lib/tailscale
echo "${TAILSCALE_STATE_MYPROJECT}" | sudo tee /var/lib/tailscale/tailscaled.state > /dev/null
fi
sudo tailscaled
- name: tailscale
command: |
if [ -n "${TAILSCALE_STATE_MYPROJECT}" ]; then
sudo -E tailscale up --accept-routes --hostname "gitpod-${GITPOD_GIT_USER_NAME// /-}-$(echo ${GITPOD_WORKSPACE_CONTEXT} | jq -r .repository.name)"
else
sudo -E tailscale up --accept-routes --hostname "gitpod-${GITPOD_GIT_USER_NAME// /-}-$(echo ${GITPOD_WORKSPACE_CONTEXT} | jq -r .repository.name)"
# store the tailscale state into gitpod user
gp env TAILSCALE_STATE_MYPROJECT="$(sudo cat /var/lib/tailscale/tailscaled.state)"
fi
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.github/ @JeremyTheocharis @Scarjit
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ input:
password: 'your-password' # optional
```

## Development and Testing
## Testing

We execute automated tests and verify that benthos-umh works:
- (WAGO PFC100, 750-8101) Connect Anonymously
- (WAGO PFC100, 750-8101) Connect Username / Password
- (WAGO PFC100, 750-8101) Connect and get one float number

These tests are executed with a local github runner called "hercules", which is connected to a isolated testing network.

## Development

### Quickstart
Follow the steps below to set up your development environment and run tests:
Expand All @@ -173,6 +182,11 @@ $ npm test

### Additional Checks and Commands

#### Gitpod and Tailscale

By default when opening the repo in Gitpod, everything that you need should start automatically. If you want to connect to our local PLCs in our office, you can use tailscale, which you will be prompted to install.
See also: https://www.gitpod.io/docs/integrations/tailscale

#### For Go Code:

1. **Linting**: Run `make lint` to check for linting errors. If any are found, you can automatically fix them by running `make format`.
Expand Down
36 changes: 22 additions & 14 deletions plugin/opcua.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ var OPCUAConfigSpec = service.NewConfigSpec().
Field(service.NewStringField("password").Description("The password to connect to the server. Defaults to none.").Default("")).
Field(service.NewStringListField("nodeIDs").Description("The OPC-UA node IDs to start the browsing."))

func ParseNodeIDs(incomingNodes []string) []*ua.NodeID {

// Parse all nodeIDs to validate them.
// loop through all nodeIDs, parse them and put them into a slice
parsedNodeIDs := make([]*ua.NodeID, len(incomingNodes))

for _, id := range incomingNodes {
parsedNodeID, err := ua.ParseNodeID(id)
if err != nil {
return nil
}

parsedNodeIDs = append(parsedNodeIDs, parsedNodeID)
}

return parsedNodeIDs
}

func newOPCUAInput(conf *service.ParsedConfig, mgr *service.Resources) (service.BatchInput, error) {
endpoint, err := conf.FieldString("endpoint")
if err != nil {
Expand All @@ -216,18 +234,7 @@ func newOPCUAInput(conf *service.ParsedConfig, mgr *service.Resources) (service.
return nil, errors.New("no nodeIDs provided")
}

// Parse all nodeIDs to validate them.
// loop through all nodeIDs, parse them and put them into a slice
parsedNodeIDs := make([]*ua.NodeID, len(nodeIDs))

for _, id := range nodeIDs {
parsedNodeID, err := ua.ParseNodeID(id)
if err != nil {
return nil, err
}

parsedNodeIDs = append(parsedNodeIDs, parsedNodeID)
}
parsedNodeIDs := ParseNodeIDs(nodeIDs)

m := &OPCUAInput{
endpoint: endpoint,
Expand Down Expand Up @@ -384,7 +391,8 @@ func (g *OPCUAInput) Connect(ctx context.Context) error {
opts = append(opts, opcua.PrivateKey(pk), opcua.Certificate(cert.Certificate[0]))

// Step 6: Create and connect the OPC UA client
c, err = opcua.NewClient(selectedEndpoint.EndpointURL, opts...)
// Note that we are not taking `selectedEndpoint.EndpointURL` here as the server can be misconfigured. We are taking instead the user input.
c, err = opcua.NewClient(g.endpoint, opts...)
if err != nil {
g.log.Errorf("Failed to create a new client")
return err
Expand All @@ -396,7 +404,7 @@ func (g *OPCUAInput) Connect(ctx context.Context) error {
return err
}

g.log.Infof("Connected to %s", selectedEndpoint.EndpointURL)
g.log.Infof("Connected to %s", g.endpoint)
g.log.Infof("Please note that browsing large node trees can take a long time (around 5 nodes per second)")

g.client = c
Expand Down
Loading